Fix memory leaks in parson_object_set_* when object is invalid

This commit is contained in:
Dan Ellis 2019-11-11 14:05:45 -08:00
parent c5bb9557fe
commit 9e1de5086f

View File

@ -1776,19 +1776,39 @@ JSON_Status json_object_set_value(JSON_Object *object, const char *name, JSON_Va
}
JSON_Status json_object_set_string(JSON_Object *object, const char *name, const char *string) {
return json_object_set_value(object, name, json_value_init_string(string));
JSON_Value *value = json_value_init_string(string);
JSON_Status status = json_object_set_value(object, name, value);
if (status == JSONFailure) {
json_value_free(value);
}
return status;
}
JSON_Status json_object_set_number(JSON_Object *object, const char *name, double number) {
return json_object_set_value(object, name, json_value_init_number(number));
JSON_Value *value = json_value_init_number(number);
JSON_Status status = json_object_set_value(object, name, value);
if (status == JSONFailure) {
json_value_free(value);
}
return status;
}
JSON_Status json_object_set_boolean(JSON_Object *object, const char *name, int boolean) {
return json_object_set_value(object, name, json_value_init_boolean(boolean));
JSON_Value *value = json_value_init_boolean(boolean);
JSON_Status status = json_object_set_value(object, name, value);
if (status == JSONFailure) {
json_value_free(value);
}
return status;
}
JSON_Status json_object_set_null(JSON_Object *object, const char *name) {
return json_object_set_value(object, name, json_value_init_null());
JSON_Value *value = json_value_init_null();
JSON_Status status = json_object_set_value(object, name, value);
if (status == JSONFailure) {
json_value_free(value);
}
return status;
}
JSON_Status json_object_dotset_value(JSON_Object *object, const char *name, JSON_Value *value) {