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

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



Further to my last post, here's a patch which fixes the same problem in:

xmlDocContentDumpOutput()
xmlNodeDumpOutput()
xmlElemDump()

(as well as the original fix for xmlNodeDump() )

As I say, though, maybe I'm missing something or have made an incorrect
assumption about how these functions should be used, and this isn't really
a mem leak at all?

Thanks,

Steve

On Wed, 3 Mar 2004, 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().
>
> 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
>
> PS - Daniel, sorry for the previous send of this email, I accidentally
> sent from a different, non-subscribed address
*** tree.c	Wed Mar  3 15:38:45 2004
--- tree.c.old	Wed Mar  3 15:37:21 2004
***************
*** 7227,7234 ****
      use = buf->use;
      xmlNodeDumpOutput(outbuf, doc, cur, level, format, NULL);
      xmlFree(outbuf);
-     xmlCleanupParser();
-     
      ret = buf->use - use;
      return (ret);
  }
--- 7227,7232 ----
***************
*** 7274,7280 ****
      } else
          xmlNodeDumpOutput(outbuf, doc, cur, 0, 1, NULL);
      xmlOutputBufferClose(outbuf);
-     xmlCleanupParser();
  }
  
  /************************************************************************
--- 7272,7277 ----
***************
*** 7718,7724 ****
      else
  #endif
          xmlNodeDumpOutputInternal(buf, doc, cur, level, format, encoding);
-     xmlCleanupParser();
  }
  
  /**
--- 7715,7720 ----
***************
*** 7800,7807 ****
      }
      if (encoding != NULL)
          cur->encoding = oldenc;
- 
-     xmlCleanupParser();
  }
  #endif /* LIBXML_OUTPUT_ENABLED */
  
--- 7796,7801 ----


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