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

[xml] Possible memory leak in xmlNodeDump()



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().

Removing the call to xmlInitParser() would probably also fix it, but I'm
not 100% sure if it's needed or not. (It wasn't present in v2.5.3)

Or maybe I'm using xmlNodeDump() incorrectly? Is there some other cleanup
function I should be calling?

Thanks,

Steve
*** tree.c.old	Wed Mar  3 14:24:17 2004
--- tree.c	Sun Feb 22 22:14:35 2004
***************
*** 7228,7236 ****
      xmlNodeDumpOutput(outbuf, doc, cur, level, format, NULL);
      xmlFree(outbuf);
      ret = buf->use - use;
- 
-     xmlCleanupParser();
- 
      return (ret);
  }
  
--- 7228,7233 ----


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