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 leakage occurs in yajl_tree_parse in case invalid json #113

Open
beelyl0 opened this issue Sep 17, 2013 · 2 comments
Open

Memory leakage occurs in yajl_tree_parse in case invalid json #113

beelyl0 opened this issue Sep 17, 2013 · 2 comments

Comments

@beelyl0
Copy link

beelyl0 commented Sep 17, 2013

We just used you library and checked it in case invalid json through valgrind ( soft for detecting mem leaks and other errors ), we had memory leaks,
my json that i tested:
{
"key" : "value
}

My peace of code:
node = yajl_tree_parse((const char *) data, errbuf, sizeof (errbuf));
if (node == NULL) {
return NULL;
}

Valgrind report:
==14281== Memcheck, a memory error detector
==14281== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==14281== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==14281== Command: ./json_parser_libtest
==14281==
==14281==
==14281== HEAP SUMMARY:
==14281== in use at exit: 414 bytes in 5 blocks
==14281== total heap usage: 13 allocs, 8 frees, 896 bytes allocated
==14281==
==14281== 18 bytes in 1 blocks are definitely lost in loss record 2 of 5
==14281== at 0x402B9FD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==14281== by 0x4128524: (below main) (in /lib/libc-2.17.so)
==14281==
==14281== 44 (12 direct, 32 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 5
==14281== at 0x402B9FD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==14281== by 0x41098E7: handle_start_map (yajl_tree.c:339)
==14281== by 0x410573D: yajl_do_parse (yajl_parser.c:269)
==14281== by 0x41022E4: yajl_parse (yajl.c:130)
==14281== by 0x4109BB5: yajl_tree_parse (yajl_tree.c:435)
==14281== by 0x40450DE: json_parser (json.c:175)
==14281== by 0x8048A73: main (json_parser_libtest.c:38)
==14281==
==14281== LEAK SUMMARY:
==14281== definitely lost: 30 bytes in 2 blocks
==14281== indirectly lost: 32 bytes in 2 blocks
==14281== possibly lost: 0 bytes in 0 blocks
==14281== still reachable: 352 bytes in 1 blocks
==14281== suppressed: 0 bytes in 0 blocks
==14281== Reachable blocks (those to which a pointer was found) are not shown.
==14281== To see them, rerun with: --leak-check=full --show-reachable=yes
==14281==
==14281== For counts of detected and suppressed errors, rerun with: -v
==14281== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

@savagecm
Copy link

savagecm commented Jun 2, 2017

I met the same issue, anyone got an idea? @halostatue @mirek @beelyl0 @bluemarvin @tjw

@Jesin
Copy link

Jesin commented Jun 5, 2017

#168 should fix it.

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