How to solve memory leak problem in libxml2?

2

I am making an application, however I am having problems with memory leak when I use libxml2, I already removed all the code to isolate only the libxml2 and still I have the memory leak error when I use valgrind, how can I solve this problem ?

This is an example code, where I'm just trying to open an xml file to parse:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libxml/parser.h>

/*
 * 
 */
int main(int argc, char** argv) {

    xmlDoc *document = NULL;
    xmlInitParser();
    document = xmlReadFile("./parameter.xml", NULL, 0);
    if (document == NULL) {
        printf("Failure on read xml file\r\n");
        exit(EXIT_FAILURE);
    }
    if (document != NULL) {
        xmlFreeDoc(document);
    }
    /*
     * Cleanup function for the XML library.
     */
    xmlCleanupParser();
    /*
     * this is to debug memory for regression tests
     */
    xmlMemoryDump();
    exit(EXIT_SUCCESS);
}

This is the valgrind command I am using to see if there is a memory leak.

valgrind --leak-check=full --show-leak-kinds=all --tool=memcheck --leak-check=yes ./test

This is the result of valgrind.

==21214== Command: ./test
==21214==
==21214==
==21214== HEAP SUMMARY:
==21214==     in use at exit: 76 bytes in 2 blocks
==21214==   total heap usage: 128 allocs, 126 frees, 128,784 bytes allocated
==21214==
==21214== 32 bytes in 1 blocks are still reachable in loss record 1 of 2
==21214==    at 0x4C2DBC5: calloc (vg_replace_malloc.c:711)
==21214==    by 0x589760E: _dlerror_run (dlerror.c:141)
==21214==    by 0x5896F81: [email protected]@GLIBC_2.2.5 (dlopen.c:87)
==21214==    by 0x7F564D5: ??? (in /lib/x86_64-linux-gnu/liblzma.so.5.2.2)
==21214==    by 0x7F5CDC7: lzma_auto_decoder (in /lib/x86_64-linux-gnu/liblzma.so.5.2.2)
==21214==    by 0x4F93CE4: ??? (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==    by 0x4F95267: __libxml2_xzread (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==    by 0x4EA94E8: ??? (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==    by 0x4EAB318: xmlParserInputBufferGrow (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==    by 0x4E707A4: xmlParserInputGrow (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==    by 0x4E76BB3: ??? (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==    by 0x4E8C194: xmlParseDocument (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==
==21214== 44 bytes in 1 blocks are still reachable in loss record 2 of 2
==21214==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==21214==    by 0x400F510: _dl_signal_error (dl-error.c:90)
==21214==    by 0x40138CC: _dl_open (dl-open.c:714)
==21214==    by 0x5896EE8: dlopen_doit (dlopen.c:66)
==21214==    by 0x400F753: _dl_catch_error (dl-error.c:187)
==21214==    by 0x5897530: _dlerror_run (dlerror.c:163)
==21214==    by 0x5896F81: [email protected]@GLIBC_2.2.5 (dlopen.c:87)
==21214==    by 0x7F564D5: ??? (in /lib/x86_64-linux-gnu/liblzma.so.5.2.2)
==21214==    by 0x7F5CDC7: lzma_auto_decoder (in /lib/x86_64-linux-gnu/liblzma.so.5.2.2)
==21214==    by 0x4F93CE4: ??? (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==    by 0x4F95267: __libxml2_xzread (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==    by 0x4EA94E8: ??? (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==21214==
==21214== LEAK SUMMARY:
==21214==    definitely lost: 0 bytes in 0 blocks
==21214==    indirectly lost: 0 bytes in 0 blocks
==21214==      possibly lost: 0 bytes in 0 blocks
==21214==    still reachable: 76 bytes in 2 blocks
==21214==         suppressed: 0 bytes in 0 blocks
==21214==
==21214== For counts of detected and suppressed errors, rerun with: -v
==21214== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    
asked by anonymous 22.02.2018 / 11:35

0 answers