lloyd / yajl

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

incorrect input JSON-file: there is a memory leak ! #191

Open EduardShaid opened 8 years ago

EduardShaid commented 8 years ago

When incorrect input JSON-file, an error occurs as a result of which not all the memory is freed ! There is a memory leak !!!

w32zhong commented 8 years ago

I think yajl is doing a bad job managing memory. Even if pass in a correct JSON file, I can observe at least two double-frees. This is the reason I switched to Parson.

novoglen commented 8 years ago

Hi @t-k-, could you please kindly point out where the two double-frees you found?

w32zhong commented 8 years ago

@novoglen. To show the problem I mentioned, I just pushed a commit (d47f90c7dfc4c373f70cf96e72526c7cbf577683) to my forked Yajl.

Actually there are 3 extra free().

$ ./configure
$ make
$ ./build/test/mleak/yajl_mleak
Total memory allocs: 11.
Unfree memory allocs: -3.

I did not take too much time looking at yajl code, not even trying to figure out how this happened, all I know is it has negative unfree counter. Although I see yajl has hooks for detecting memory leaks (e.g. using yajl_alloc_funcs in yajl_test.c), but that is not enough, since src code is still using un-wrapped realloc() malloc() and free() everywhere (see yajl_tree.c). So I simply do not trust numMallocs and numFrees used in yajl's memory leak detection, thus my commit uses linker hooks to show there is extra free().

Jesin commented 7 years ago

168 should fix this.