Skip to content

Commit 0d10e27

Browse files
committed
fix #55 memory leak in cJSON_ReplaceItemInObject
1 parent 9e31049 commit 0d10e27

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cJSON.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,12 @@ void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem
18611861
}
18621862
if(c)
18631863
{
1864+
/* free the old string if not const */
1865+
if (!(newitem->type & cJSON_StringIsConst) && newitem->string)
1866+
{
1867+
cJSON_free(newitem->string);
1868+
}
1869+
18641870
newitem->string = cJSON_strdup(string);
18651871
cJSON_ReplaceItemInArray(object, i, newitem);
18661872
}

0 commit comments

Comments
 (0)