mirror of
https://github.com/kgabis/parson.git
synced 2024-11-24 06:05:29 +00:00
Fix memory leaks in parson_object_set_*
when object
is invalid
This commit is contained in:
parent
c5bb9557fe
commit
9e1de5086f
28
parson.c
28
parson.c
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user