Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak for json_tokener_parse_ex for version 0.12.1 #382

Closed
mariusor opened this issue Nov 27, 2017 · 2 comments
Closed

Memory leak for json_tokener_parse_ex for version 0.12.1 #382

mariusor opened this issue Nov 27, 2017 · 2 comments

Comments

@mariusor
Copy link

mariusor commented Nov 27, 2017

Hi, using a very simple example of json parsing, valgrind reports a memory leak for function json_tokener_parse_ex:

 ==19276== 711 (88 direct, 623 indirect) bytes in 1 blocks are definitely lost in loss record 11 of 11                                                                                                                                      
 ==19276==    at 0x4C2EF35: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)                                                                                                                                                 
 ==19276==    by 0x59E5F1A: lh_table_new (in /usr/lib/libjson-c.so.2.0.2)                                                                                                                                                                   
 ==19276==    by 0x59E26AD: json_object_new_object (in /usr/lib/libjson-c.so.2.0.2)                                                                                                                                                                 
 ==19276==    by 0x59E49A4: json_tokener_parse_ex (in /usr/lib/libjson-c.so.2.0.2)                                                                                                                                                          
 ==19276==    by 0x10E0EB: json_document_is_error (api.h:1044)    

The code triggering this can be seen in my project mpris-scrobbler.

The buffer string that would be matched is something like:

{"error":4,"message":"Unauthorized Token - This token has not been issued"}

Looking at the code, it seems that somehow the json_object_object_delete function is not called anywhere relevant, even though I'm calling json_tokener_free().

I have tried also using the simple case with just json_tokener_parse(buffer), but the memory leak is still there.

Is there something I'm overlooking? Like an extra step for freeing that I missed in the documentation?

Library version:

pkg-config --print-provides json-c
json-c = 0.12.1
@rgerhards
Copy link
Contributor

did you free (_put) the object the tokener returned?

@mariusor
Copy link
Author

I wasn't. Thank you.

Maybe it's not clear enough in the documentation but it wasn't obvious for me that this is the mechanism for cleaning up and freeing resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants