mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
handle null pointers: create_reference
Also fixes a potential memory leak
This commit is contained in:
parent
e9d1de24cf
commit
90ff72c8bb
21
cJSON.c
21
cJSON.c
@ -1756,16 +1756,23 @@ static void suffix_object(cJSON *prev, cJSON *item)
|
|||||||
/* Utility for handling references. */
|
/* Utility for handling references. */
|
||||||
static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks)
|
static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks)
|
||||||
{
|
{
|
||||||
cJSON *ref = cJSON_New_Item(hooks);
|
cJSON *reference = NULL;
|
||||||
if (!ref)
|
if (item == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(ref, item, sizeof(cJSON));
|
|
||||||
ref->string = NULL;
|
reference = cJSON_New_Item(hooks);
|
||||||
ref->type |= cJSON_IsReference;
|
if (reference == NULL)
|
||||||
ref->next = ref->prev = NULL;
|
{
|
||||||
return ref;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(reference, item, sizeof(cJSON));
|
||||||
|
reference->string = NULL;
|
||||||
|
reference->type |= cJSON_IsReference;
|
||||||
|
reference->next = reference->prev = NULL;
|
||||||
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add item to array/object. */
|
/* Add item to array/object. */
|
||||||
|
Loading…
Reference in New Issue
Block a user