1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix a memory leak when inserting into an object with an already-present key

This commit is contained in:
Stephen Dolan
2012-09-01 18:24:17 +01:00
parent 66fd702363
commit 92654f8204

6
c/jv.c
View File

@@ -602,6 +602,7 @@ static jv* jvp_object_write(jv_complex* object, jvp_string* key) {
jvp_string_free_p(key);
} else {
slot = jvp_object_add_slot(object, key, bucket);
slot->value = jv_null();
}
if (slot == 0) {
jvp_object_rehash(object);
@@ -609,6 +610,7 @@ static jv* jvp_object_write(jv_complex* object, jvp_string* key) {
assert(!jvp_object_find_slot(object, key, bucket));
slot = jvp_object_add_slot(object, key, bucket);
assert(slot);
slot->value = jv_null();
}
return &slot->value;
}
@@ -654,7 +656,9 @@ jv jv_object_set(jv object, jv key, jv value) {
assert(jv_get_kind(object) == JV_KIND_OBJECT);
assert(jv_get_kind(key) == JV_KIND_STRING);
// copy/free of object, key, value coalesced
*jvp_object_write(&object.val.complex, jvp_string_ptr(&key.val.complex)) = value;
jv* slot = jvp_object_write(&object.val.complex, jvp_string_ptr(&key.val.complex));
jv_free(*slot);
*slot = value;
return object;
}