]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Fix a memory leak in test1 with respect to how json_object_object_del was used.
authorEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 17 Sep 2012 01:49:22 +0000 (20:49 -0500)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 17 Sep 2012 01:49:22 +0000 (20:49 -0500)
tests/test1.c
tests/test1.expected
tests/test1Formatted_plain.expected
tests/test1Formatted_pretty.expected
tests/test1Formatted_spaced.expected

index 8157846ae56afc08ca5e86332d1481282988a8f2..0c483a596ce2de18f94a5cb029cf549b8454a560 100644 (file)
@@ -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)
index 6653fe0bc5a98d3778c65d17589f4b3918b76b76..e36aaa4c4f43630d82f505feb212fd2cf9190cb8 100644 (file)
@@ -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"
index 65b19ed99fa9fd7c546af628051a2d7ca4a3239c..edcc1b932812da7aa788c4b6815515ba9e56a18e 100644 (file)
@@ -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"
index f2334c4abc4d3273152203dc3d5c53c329d2ba72..95e48ed0102a8b2fd82864af0731c3520f0d510c 100644 (file)
@@ -45,6 +45,7 @@ my_array.to_string()=[
   2,
   3
 ]
+baz_obj.to_string()="fark"
 my_object=
        abc: 12
        foo: "bar"
index 6653fe0bc5a98d3778c65d17589f4b3918b76b76..e36aaa4c4f43630d82f505feb212fd2cf9190cb8 100644 (file)
@@ -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"