Browse Source

Fix a memory leak in test1 with respect to how json_object_object_del was used.

tags/json-c-0.11-20130402
Eric Haszlakiewicz 13 years ago
parent
commit
c3d1d597ab
5 changed files with 12 additions and 1 deletions
  1. +8
    -1
      tests/test1.c
  2. +1
    -0
      tests/test1.expected
  3. +1
    -0
      tests/test1Formatted_plain.expected
  4. +1
    -0
      tests/test1Formatted_pretty.expected
  5. +1
    -0
      tests/test1Formatted_spaced.expected

+ 8
- 1
tests/test1.c View 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)


+ 1
- 0
tests/test1.expected View 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"


+ 1
- 0
tests/test1Formatted_plain.expected View 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"


+ 1
- 0
tests/test1Formatted_pretty.expected View File

@@ -45,6 +45,7 @@ my_array.to_string()=[
2,
3
]
baz_obj.to_string()="fark"
my_object=
abc: 12
foo: "bar"


+ 1
- 0
tests/test1Formatted_spaced.expected View 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"


Loading…
Cancel
Save