Possible memory leak problem
When I was using the libxml2 library, I found that it might have a memory leak. The memory leak situation is saved as html content encoding as non utf-8.
The version of the library is libxml2-2.9.9. The OS is CentOS Linux release 7.2.1511 (Core).
I attach an example program that demonstrates this. test_libxml.c test.html
$ valgrind --leak-check=full --tool=memcheck --leak-check=full ./test_libxml.out test.html gbk
will get:
==28150== HEAP SUMMARY:
==28150== in use at exit: 65,996 bytes in 8 blocks
==28150== total heap usage: 854 allocs, 846 frees, 418,862 bytes allocated
==28150==
==28150== 65,996 (40 direct, 65,956 indirect) bytes in 1 blocks are definitely lost in loss record 8 of 8
==28150== at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
==28150== by 0x4E68A77: xmlFindCharEncodingHandler (encoding.c:1700)
==28150== by 0x4F418A5: xmlNewSaveCtxt (xmlsave.c:395)
==28150== by 0x4F41CD3: xmlSaveToBuffer (xmlsave.c:1867)
==28150== by 0x400EBE: save (test_libxml.c:61)
==28150== by 0x40101B: main (test_libxml.c:114)
==28150==
==28150== LEAK SUMMARY:
==28150== definitely lost: 40 bytes in 1 blocks
==28150== indirectly lost: 65,956 bytes in 7 blocks
==28150== possibly lost: 0 bytes in 0 blocks
==28150== still reachable: 0 bytes in 0 blocks
==28150== suppressed: 0 bytes in 0 blocks
Is it necessary to check if the ctxt->handler is released when the function xmlFreeSaveCtxt() is called?
Edited by Nick Wellnhofer