lloyd / yajl

A fast streaming JSON parsing library in C.
http://lloyd.github.com/yajl
ISC License
2.15k stars 435 forks source link

Memory leak with yajl_tree_parse in yajl version 2.1.0 #223

Open RambabuTirumalasetty opened 4 years ago

RambabuTirumalasetty commented 4 years ago

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 commented 4 years ago

Can you please help on the above query.

Thanks,

robohack commented 4 years ago

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.