From: Eric Haszlakiewicz Date: Mon, 17 Sep 2012 01:49:22 +0000 (-0500) Subject: Fix a memory leak in test1 with respect to how json_object_object_del was used. X-Git-Tag: json-c-0.11-20130402~40 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=c3d1d597abb6261a6c874bd6315a73fe4dbb8e7f;p=thirdparty%2Fjson-c.git Fix a memory leak in test1 with respect to how json_object_object_del was used. --- diff --git a/tests/test1.c b/tests/test1.c index 8157846a..0c483a59 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -107,8 +107,15 @@ int main(int argc, char **argv) json_object_object_add(my_object, "bool0", json_object_new_boolean(0)); json_object_object_add(my_object, "bool1", json_object_new_boolean(1)); json_object_object_add(my_object, "baz", json_object_new_string("bang")); - json_object_object_add(my_object, "baz", json_object_new_string("fark")); + + json_object *baz_obj = json_object_new_string("fark"); + json_object_object_add(my_object, "baz", baz_obj); json_object_object_del(my_object, "baz"); + + /* baz_obj should still be valid */ + printf("baz_obj.to_string()=%s\n", json_object_to_json_string(baz_obj)); + json_object_put(baz_obj); + /*json_object_object_add(my_object, "arr", my_array);*/ printf("my_object=\n"); json_object_object_foreach(my_object, key, val) diff --git a/tests/test1.expected b/tests/test1.expected index 6653fe0b..e36aaa4c 100644 --- a/tests/test1.expected +++ b/tests/test1.expected @@ -27,6 +27,7 @@ my_array= [3]=2 [4]=3 my_array.to_string()=[ null, 0, 1, 2, 3 ] +baz_obj.to_string()="fark" my_object= abc: 12 foo: "bar" diff --git a/tests/test1Formatted_plain.expected b/tests/test1Formatted_plain.expected index 65b19ed9..edcc1b93 100644 --- a/tests/test1Formatted_plain.expected +++ b/tests/test1Formatted_plain.expected @@ -27,6 +27,7 @@ my_array= [3]=2 [4]=3 my_array.to_string()=[null,0,1,2,3] +baz_obj.to_string()="fark" my_object= abc: 12 foo: "bar" diff --git a/tests/test1Formatted_pretty.expected b/tests/test1Formatted_pretty.expected index f2334c4a..95e48ed0 100644 --- a/tests/test1Formatted_pretty.expected +++ b/tests/test1Formatted_pretty.expected @@ -45,6 +45,7 @@ my_array.to_string()=[ 2, 3 ] +baz_obj.to_string()="fark" my_object= abc: 12 foo: "bar" diff --git a/tests/test1Formatted_spaced.expected b/tests/test1Formatted_spaced.expected index 6653fe0b..e36aaa4c 100644 --- a/tests/test1Formatted_spaced.expected +++ b/tests/test1Formatted_spaced.expected @@ -27,6 +27,7 @@ my_array= [3]=2 [4]=3 my_array.to_string()=[ null, 0, 1, 2, 3 ] +baz_obj.to_string()="fark" my_object= abc: 12 foo: "bar"