From 0d10e279c8b604f71829b5d49d092719f4ae96b6 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Fri, 11 Nov 2016 11:53:14 +0700 Subject: [PATCH] fix #55 memory leak in cJSON_ReplaceItemInObject --- cJSON.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cJSON.c b/cJSON.c index 0fd8c3e..ae70fc6 100644 --- a/cJSON.c +++ b/cJSON.c @@ -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); }