Re: [xml] Possible memory leak in xmlNodeDump()



On Wed, Mar 03, 2004 at 02:42:10PM +0000, Steve Little wrote:
Hi,
      I'm experiencing a memory leak when using xmlNodeDump() from
libxml 2.6.7. The following short snippet recreates the problem:

------8<-------8<---------

#include <libxml/tree.h>
#include <libxml/parser.h>

int main(void){
  xmlDocPtr doc = xmlParseFile("test.xml");
  xmlBufferPtr buff = xmlBufferCreate();
  xmlNodeDump(buff,doc,doc->children,0,0);
  xmlBufferFree(buff);
  xmlFreeDoc(doc);
}

----8<-------8<------

The problem seems to be caused because there's a call to xmlInitParser()
in xmlNodeDump(), but no corresponding call to xmlCleanupParser(). The
attached patch fixes the problem by adding a call to xmlCleanupParser().

  Bzzzz, wrong ! xmlCleanupParser() must be called explicitely since
it is a library wide shutdown. Calling it from xmlNodeDump() or any 
other funtion is not proper. If you shutdown the library then you call
xmlNodeDump(). xmlInitParser() is idempotent if the library is already 
initialized, that's why the call is made from xmlNodeDump(), it is also
made from the first call to xmlParseFile() actually ...

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
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]