[xml] [PATCH]memory leak in xmlSaveClose



running valgrind over this code

  std::string document::xml() const 
  { 
    std::string s; 
 
    xmlSaveCtxtPtr writer = xmlSaveToIO(ddixml_writer, ddixml_closer, (void*)&s, 0, 0)$
    if (0 == writer) DDIXML_THROW_EXCEPTION("failed to create save context."); 
 
    xmlSaveDoc(writer, _doc); 
    xmlSaveClose(writer); 
 
    return s; 
  }

gives me:

==23595== 32 bytes in 1 blocks are definitely lost in loss record 3 of 6
==23595==    at 0x3C02140D: malloc (vg_replace_malloc.c:105)
==23595==    by 0x3C0C64A2: xmlAllocOutputBuffer (in /usr/lib/libxml2.so.2.6.9)
==23595==    by 0x3C0C6E4A: xmlOutputBufferCreateIO (in /usr/lib/libxml2.so.2.6.9)
==23595==    by 0x3C149620: xmlSaveToIO (in /usr/lib/libxml2.so.2.6.9)

something like this should fix it:

--- libxml2-2.6.9/xmlsave.c.orig        2004-04-28 14:36:03.000000000 -0400
+++ libxml2-2.6.9/xmlsave.c     2004-04-28 14:36:22.000000000 -0400
@@ -1332,6 +1332,7 @@ xmlSaveClose(xmlSaveCtxtPtr ctxt)
 
     if (ctxt == NULL) return(-1);
     ret = xmlSaveFlush(ctxt);
+               xmlOutputBufferClose(ctxt->buf);
     xmlFreeSaveCtxt(ctxt);
     return(ret);
 }

i don't know the code enough to know if xmlOutputBufferClose should be prefixed by
a ctxt->buf == NULL check...

jr

-- 
------------------------------------------------------------
Joel W. Reed                                    412-257-3881
----------   http://home.comcast.net/~joelwreed/  ----------



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