mirror of
https://github.com/DaveGamble/cJSON
synced 2024-12-22 14:42:06 +00:00
Set free'd pointers to NULL whenever they are not reassigned immediately after
This commit is contained in:
parent
5437b79086
commit
1ac905d3b2
8
cJSON.c
8
cJSON.c
@ -235,10 +235,12 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item)
|
|||||||
if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL))
|
if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL))
|
||||||
{
|
{
|
||||||
global_hooks.deallocate(item->valuestring);
|
global_hooks.deallocate(item->valuestring);
|
||||||
|
item->valuestring = NULL;
|
||||||
}
|
}
|
||||||
if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
|
if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
|
||||||
{
|
{
|
||||||
global_hooks.deallocate(item->string);
|
global_hooks.deallocate(item->string);
|
||||||
|
item->string = NULL;
|
||||||
}
|
}
|
||||||
global_hooks.deallocate(item);
|
global_hooks.deallocate(item);
|
||||||
item = next;
|
item = next;
|
||||||
@ -820,6 +822,7 @@ fail:
|
|||||||
if (output != NULL)
|
if (output != NULL)
|
||||||
{
|
{
|
||||||
input_buffer->hooks.deallocate(output);
|
input_buffer->hooks.deallocate(output);
|
||||||
|
output = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input_pointer != NULL)
|
if (input_pointer != NULL)
|
||||||
@ -1165,6 +1168,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
|
|||||||
|
|
||||||
/* free the buffer */
|
/* free the buffer */
|
||||||
hooks->deallocate(buffer->buffer);
|
hooks->deallocate(buffer->buffer);
|
||||||
|
buffer->buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return printed;
|
return printed;
|
||||||
@ -1173,11 +1177,13 @@ fail:
|
|||||||
if (buffer->buffer != NULL)
|
if (buffer->buffer != NULL)
|
||||||
{
|
{
|
||||||
hooks->deallocate(buffer->buffer);
|
hooks->deallocate(buffer->buffer);
|
||||||
|
buffer->buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printed != NULL)
|
if (printed != NULL)
|
||||||
{
|
{
|
||||||
hooks->deallocate(printed);
|
hooks->deallocate(printed);
|
||||||
|
printed = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1218,6 +1224,7 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON
|
|||||||
if (!print_value(item, &p))
|
if (!print_value(item, &p))
|
||||||
{
|
{
|
||||||
global_hooks.deallocate(p.buffer);
|
global_hooks.deallocate(p.buffer);
|
||||||
|
p.buffer = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2987,4 +2994,5 @@ CJSON_PUBLIC(void *) cJSON_malloc(size_t size)
|
|||||||
CJSON_PUBLIC(void) cJSON_free(void *object)
|
CJSON_PUBLIC(void) cJSON_free(void *object)
|
||||||
{
|
{
|
||||||
global_hooks.deallocate(object);
|
global_hooks.deallocate(object);
|
||||||
|
object = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user