Merge pull request #128 from danellis/master

Fix memory leaks in `parson_object_set_*` when `object` is invalid
This commit is contained in:
Krzysztof Gabis 2019-11-12 08:57:48 +01:00 committed by GitHub
commit 39c2d51c52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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) {