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 with yajl_tree_parse in yajl version 2.1.0 #223

Open
RambabuTirumalasetty opened this issue Nov 12, 2019 · 2 comments
Open

Memory leak with yajl_tree_parse in yajl version 2.1.0 #223

RambabuTirumalasetty opened this issue Nov 12, 2019 · 2 comments

Comments

@RambabuTirumalasetty
Copy link

Hi,

We feed 32KB in yajl_tree_parse() API, which took 220KB of memory for processing. Once the parsing finished, we freed the root by using yajl_tree_free() API.

200KB of memory only freed out of 220KB, remaining 20KB of memory is not freed.

Please find our reference code below.

yajl_val node1;
node1 = yajl_tree_parse( testJSON, errbuf, sizeof(errbuf));
   yajl_tree_free(node1);

After freeing node1 is pointing to some data, it is not NULL.
Could you please provide your input on this.
Kindly do needful ASAP.

Thanks.

@subithaparamasivan
Copy link

subithaparamasivan commented Nov 13, 2019

Can you please help on the above query.

Thanks,

@robohack
Copy link

In C when you free an object by calling free() and passing a pointer that points to that object, the pointer does not get set to NULL, nor do (usually) the contents of memory at the address still pointed to by the pointer change in any way, at least not immediately and especially not in a single-threaded program.

The best way to detect the source of memory leaks is to use Valgrind. Run your program, or a similar enough test program, under Valgrind with the test data and it will report each and every memory block that is not freed, and it will give a stack backtrace to the location each group of similar blocks was allocated.

robohack added a commit to robohack/yajl that referenced this issue Jul 17, 2023
- use wrapped malloc() et al wrappers consistently
- update example/parse_config.c to do memory leak detection
- add a regression test using example/parse_config

Several issues in lloyd/yajl complained about this leak, and comments in
lloyd/yajl#102 showed a mostly correct fix though none of these issues
mentioned or actually fixed the directly related error reporting
problem.

Fixes lloyd/yajl#102, fixes lloyd/yajl#113, fixes lloyd/yajl#168, fixes
lloyd/yajl#191, fixes lloyd/yajl#223, fixes lloyd/yajl#250.  Also fixes
lloy/yajl#185.
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

3 participants