Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 542fb0e

Browse files
maebexAlanscut
authored andcommitted
Set free'd pointers to NULL whenever they are not reassigned immediately after
1 parent a20be79 commit 542fb0e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

‎cJSON.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,12 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item)
263263
if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL))
264264
{
265265
global_hooks.deallocate(item->valuestring);
266+
item->valuestring = NULL;
266267
}
267268
if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
268269
{
269270
global_hooks.deallocate(item->string);
271+
item->string = NULL;
270272
}
271273
global_hooks.deallocate(item);
272274
item = next;
@@ -894,6 +896,7 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu
894896
if (output != NULL)
895897
{
896898
input_buffer->hooks.deallocate(output);
899+
output = NULL;
897900
}
898901

899902
if (input_pointer != NULL)
@@ -1236,6 +1239,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
12361239

12371240
/* free the buffer */
12381241
hooks->deallocate(buffer->buffer);
1242+
buffer->buffer = NULL;
12391243
}
12401244

12411245
return printed;
@@ -1244,11 +1248,13 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
12441248
if (buffer->buffer != NULL)
12451249
{
12461250
hooks->deallocate(buffer->buffer);
1251+
buffer->buffer = NULL;
12471252
}
12481253

12491254
if (printed != NULL)
12501255
{
12511256
hooks->deallocate(printed);
1257+
printed = NULL;
12521258
}
12531259

12541260
return NULL;
@@ -1289,6 +1295,7 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON
12891295
if (!print_value(item, &p))
12901296
{
12911297
global_hooks.deallocate(p.buffer);
1298+
p.buffer = NULL;
12921299
return NULL;
12931300
}
12941301

@@ -3132,4 +3139,5 @@ CJSON_PUBLIC(void *) cJSON_malloc(size_t size)
31323139
CJSON_PUBLIC(void) cJSON_free(void *object)
31333140
{
31343141
global_hooks.deallocate(object);
3142+
object = NULL;
31353143
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /