Skip to content

Commit

Permalink
Fix memory leaks in parson_object_set_* when object is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ellis committed Nov 11, 2019
1 parent c5bb955 commit 9e1de50
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions parson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9e1de50

Please sign in to comment.