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

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


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

int main(void){
  xmlDocPtr doc = xmlParseFile("test.xml");
  xmlBufferPtr buff = xmlBufferCreate();


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 Veillard      | Red Hat Network
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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