[xml] Memory leak using xmlSchemaParse()



Hi!

I'm trying to validate a XML document against a XML Schema. Result is ok (using xmllint too) but when using valgrind, it indicates me memory leaks (still reachable) and errors linked to libraries's code and not to my function.

Here are valgrind results :

/LEAK SUMMARY:
==7223==    definitely lost: 0 bytes in 0 blocks.
==7223==      possibly lost: 0 bytes in 0 blocks.
==7223==    still reachable: 3,444 bytes in 48 blocks.
==7223==         suppressed: 0 bytes in 0 blocks./

/
==7223== 1 errors in context 1 of 3:
==7223== Invalid read of size 4
==7223==    at 0x4014183: (within /lib/ld-2.4.so)
==7223==    by 0x4005A89: (within /lib/ld-2.4.so)
==7223==    by 0x40077AD: (within /lib/ld-2.4.so)
==7223==    by 0x400B346: (within /lib/ld-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223==    by 0x400B53A: (within /lib/ld-2.4.so)
==7223==    by 0x40108D4: (within /lib/ld-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223==    by 0x40103C8: (within /lib/ld-2.4.so)
==7223==    by 0x4268801: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223== by 0x42689B4: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==  Address 0x4351C90 is 32 bytes inside a block of size 34 alloc'd
==7223==    at 0x4021396: malloc (vg_replace_malloc.c:149)
==7223==    by 0x4007CC7: (within /lib/ld-2.4.so)
==7223==    by 0x400B346: (within /lib/ld-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223==    by 0x400B53A: (within /lib/ld-2.4.so)
==7223==    by 0x40108D4: (within /lib/ld-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223==    by 0x40103C8: (within /lib/ld-2.4.so)
==7223==    by 0x4268801: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223== by 0x42689B4: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.4.so) ==7223== by 0x4244350: __nss_lookup_function (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==
==7223== 1 errors in context 2 of 3:
==7223== Invalid read of size 4
==7223==    at 0x4014183: (within /lib/ld-2.4.so)
==7223==    by 0x4005A89: (within /lib/ld-2.4.so)
==7223==    by 0x40077AD: (within /lib/ld-2.4.so)
==7223==    by 0x4010874: (within /lib/ld-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223==    by 0x40103C8: (within /lib/ld-2.4.so)
==7223==    by 0x4268801: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223== by 0x42689B4: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.4.so) ==7223== by 0x4244350: __nss_lookup_function (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x4219A20: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x421A715: getaddrinfo (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==  Address 0x4351958 is 32 bytes inside a block of size 35 alloc'd
==7223==    at 0x4021396: malloc (vg_replace_malloc.c:149)
==7223==    by 0x4007CC7: (within /lib/ld-2.4.so)
==7223==    by 0x4010874: (within /lib/ld-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223==    by 0x40103C8: (within /lib/ld-2.4.so)
==7223==    by 0x4268801: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223== by 0x42689B4: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.4.so) ==7223== by 0x4244350: __nss_lookup_function (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x4219A20: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x421A715: getaddrinfo (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x40CEFAB: xmlNanoHTTPConnectHost (nanohttp.c:1003)
==7223==
==7223== 1 errors in context 3 of 3:
==7223== Invalid read of size 4
==7223==    at 0x4014199: (within /lib/ld-2.4.so)
==7223==    by 0x4005A89: (within /lib/ld-2.4.so)
==7223==    by 0x40077AD: (within /lib/ld-2.4.so)
==7223==    by 0x4010874: (within /lib/ld-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223==    by 0x40103C8: (within /lib/ld-2.4.so)
==7223==    by 0x4268801: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223== by 0x42689B4: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.4.so) ==7223== by 0x4244350: __nss_lookup_function (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x4219A20: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x421A715: getaddrinfo (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==  Address 0x4351134 is 36 bytes inside a block of size 37 alloc'd
==7223==    at 0x4021396: malloc (vg_replace_malloc.c:149)
==7223==    by 0x4007CC7: (within /lib/ld-2.4.so)
==7223==    by 0x4010874: (within /lib/ld-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223==    by 0x40103C8: (within /lib/ld-2.4.so)
==7223==    by 0x4268801: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x400CA95: (within /lib/ld-2.4.so)
==7223== by 0x42689B4: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.4.so) ==7223== by 0x4244350: __nss_lookup_function (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x4219A20: (within /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x421A715: getaddrinfo (in /lib/tls/i686/cmov/libc-2.4.so)
==7223==    by 0x40CEFAB: xmlNanoHTTPConnectHost (nanohttp.c:1003)

/
And all still reachable blocks are also due to getaddrinfo().

So, according to Valgrind, the errors aren't due to my code, but after debugging it, it seems to come from the call of XmlSchemaParse(). Here is the fragment of code concerned :

int XML_SchemaValidation(char * XMLSchemaFile_pathname, buffer * xmlchar)
{
   xmlSchemaPtr ptr_schema = NULL;
   xmlSchemaParserCtxtPtr ptr_ctxt;
   xmlSchemaValidCtxtPtr ptr_validctxt;
   int vl_return = -1;
   xmlDocPtr vl_doc;


   /* Open XML Schema File*/
   ptr_ctxt = xmlSchemaNewParserCtxt(XMLSchemaFile_pathname);
   xmlSchemaSetParserErrors(ptr_ctxt,
       (xmlSchemaValidityErrorFunc) fprintf,
       (xmlSchemaValidityWarningFunc) fprintf,
       stderr);

   ptr_schema = xmlSchemaParse(ptr_ctxt);
   xmlSchemaFreeParserCtxt(ptr_ctxt);

   /* Si le XML Schema n'a pas pu être chargé*/
   if (ptr_schema == NULL){
printf("XMLSCHEMA: Could not open XML Schema %s\n", XMLSchemaFile_pathname);
       xmlSchemaCleanupTypes();
       xmlCleanupParser();
       xmlMemoryDump();
       return vl_return;
   }
....
....
xmlSchemaFree(ptr_schema);
....
}


If ptr_schema is NULL (with a bad path to my XML schema), there is no error in valgrind, but when xmlSchemaParse() returns a valid result, there are memory leaks in valgrind even if the program compiles and executes.

(I use libxml2-2.6.28.)

If you have any remarks, they are welcome!

Best regards,

Barbara Philippot





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]