Re: [xml] xmlParseFile - calling with nonexisting filename and memory leak



On Tue, Jan 01, 2008 at 06:00:51AM -0800, tam wrote:

Hi,
My server (c++/multithreaded/linux) is using libxml2 version 2.6.11.
In the startup the main thread call xmlInitParser, and in case of initiated
shutdown call to xmlCleanupParser.

A thread may call âxmlParseFileâ with nonexisting filename.
Purify point to memory-leak each time âxmlParseFileâ attempt to load
nonexisting file:
         MLK: 75 bytes leaked at 0x10f02ca0
         This memory was allocated from:
               malloc         [rtlib.o]
               xmlStrndup     [libxml2.so.2]
               xmlStrdup      [libxml2.so.2]
               xmlCopyError   [libxml2.so.2]
               __xmlRaiseError [libxml2.so.2]
               __xmlLoaderErr [libxml2.so.2]
         MLK: 41 bytes leaked at 0x18f71420
         This memory was allocated from:
               malloc         [rtlib.o]
               xmlStrndup     [libxml2.so.2]
               xmlStrdup      [libxml2.so.2]
               xmlCopyError   [libxml2.so.2]
               __xmlRaiseError [libxml2.so.2]
               __xmlLoaderErr [libxml2.so.2]

What is the right approach to catch and clean this memory?

  Using a recent version like 2.6.30 is likely to fix it.
Calling xmlResetLastError() on the thread where the error occured might
fix it on 2.6.11 too.

Should I use xmlGenericErrorFunc (void * ctx,  const char * msg) â but what
to delete?

  That would alllow to get the error reported as a function callback.
But the global variable may still be updated.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/



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