Skip to content

Commit

Permalink
fix #55 memory leak in cJSON_ReplaceItemInObject
Browse files Browse the repository at this point in the history
  • Loading branch information
FSMaxB committed Nov 11, 2016
1 parent 9e31049 commit 0d10e27
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 0d10e27

Please sign in to comment.