1
0
mirror of https://github.com/DaveGamble/cJSON synced 2024-12-23 23:22:09 +00:00

fix #55 memory leak in cJSON_ReplaceItemInObject

This commit is contained in:
Max Bruckner 2016-11-11 11:53:14 +07:00
parent 9e31049159
commit 0d10e279c8

View File

@ -1861,6 +1861,12 @@ void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem
}
if(c)
{
/* free the old string if not const */
if (!(newitem->type & cJSON_StringIsConst) && newitem->string)
{
cJSON_free(newitem->string);
}
newitem->string = cJSON_strdup(string);
cJSON_ReplaceItemInArray(object, i, newitem);
}