I'm experimenting memory errors in my C application and using valgrind, I see many strange things around the json-c lib.
So looking at some infos on the web, I saw this post about json_object_new_object
So I have 2 questions to be clear about everything: The first one is about json construction
When I add an object to another object, do I have to just free the first one ? example:
json_object * jobj1 = json_object_new_object();
json_object * jobj2 = json_object_new_object();
json_object_object_add(jobj1,"Object", jobj2);
...
json_object_put(jobj); // Is it enough to free all the json tree??
According to this post it seems to be ok, but it hasn't been really answered.
Question 2:
Looking at this tuto, it seems not necessary to free anything but looking at my valgrind log, json_object_new_object
is called:
by 0x4F7F4CF: json_object_new_object (in /lib/x86_64-linux-gnu/libjson-c.so.3.0.1)
by 0x4F81B38: json_tokener_parse_ex (in /lib/x86_64-linux-gnu/libjson-c.so.3.0.1)
by 0x4F82316: json_tokener_parse_verbose (in /lib/x86_64-linux-gnu/libjson-c.so.3.0.1)
by 0x4F8237D: json_tokener_parse (in /lib/x86_64-linux-gnu/libjson-c.so.3.0.1)
So do I have to do this ?
json_object *jobj = json_tokener_parse(...);
...
json_object_put(jobj);