Re: [xml] memory leak while parsing from memory buffer



Daniel Veillard <veillard redhat com> writes:

On Wed, Apr 07, 2004 at 07:48:49PM +0200, Petr Pajas wrote:
But, although ctxt->input->filename _does_ get freed with
xmlFreeParserCtxt, the above code leaks. If the line with xmlStrdup is
removed, the leak disappears. I suspect, that somewhere, during
xmlParseDocument some copies of filename are made but never freed or
something similar. Otherwise I don't know why this line would make any
difference. BTW, it's the same if I set

ctxt->input->filename = "";

and put 

ctxt->input->filename = NULL;

just before xmlFreeParserCtxt(ctxt).

Any hints?

  that would mean that the error handling code leaks.
For some reasons it doesn't seems to occur in the common path
of libxml2, even when trying to reproduce exactly the same prob
with a libxml2 compiled with memory debug (xmlsoft.org/memory.html):

I'm terribly sorry, it's all my fault. I didn't notice, that several
lines down we overwrite doc->URL without freeing it if non-NULL:

 SV * newURI = sv_2mortal(newSVpvf("unknown-%12.12d", (void*)real_doc));
 doc->URL = xmlStrdup((const xmlChar*)SvPV_nolen(newURI));

which is where the copy is and hence the leak. 

Thanks for your time,

-- Petr

Attachment: pgpbN4_Rkfb1h.pgp
Description: PGP signature



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