diff --git a/cJSON.c b/cJSON.c index 63fb043470706a202287b12c26e95147084dda30..291f2ea7f6d55dd9a36ddfb724c51509a298c904 100644 --- a/cJSON.c +++ b/cJSON.c @@ -567,10 +567,16 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) return NULL; } /* return NULL if the object is corrupted */ - if (object->valuestring == NULL || valuestring == NULL) + if (object->valuestring == NULL) { return NULL; } + if (valuestring == NULL) + { + cJSON_free(object->valuestring); + object->valuestring = NULL; + return NULL; + } if (strlen(valuestring) <= strlen(object->valuestring)) { strcpy(object->valuestring, valuestring);