akheron / jansson

C library for encoding, decoding and manipulating JSON data
http://www.digip.org/jansson/
Other
3.05k stars 809 forks source link

Process getting killed when using json_loads #579

Open anudeep010291 opened 3 years ago

anudeep010291 commented 3 years ago

Hi, I have an embedded device in which I have trying to read a data from a file and convert it into JSON object using json_loads.

file_str="Read data from a file"; json_t* file_read = json_loads(file_str, 0, NULL); json_object_clear(file_read);

I am clearing the json object but still the process gets killed automatically after a while with an error saying "segmentation error(core dumped)".Can someone tell what the issue is here. ?

avimagar commented 3 years ago

Can you share a stack trace of core?

ploxiln commented 3 years ago

If you use json_object_get() before json_object_clear(), then use the thing you got out of the object after the clear, that is invalid and would cause a segfault. If you will keep a reference to the thing after clearing the object, you should use json_incref() on it.