[libxml++] memory leak in SaxParser



I have encountered a memory leak (not signalized by Purify) in the class SaxParser.
in the function parse() :
 

"_context->sax = & _sax_handler;

[..]

release_underlying();"

is not valid. structure allocated in xmlCreateMemoryParserCtxt for the sax handler is never released due to

"_context->sax = 0 " in release_underlying().

The solution I have found was to use memcpy and to really release sax object of context.

I don't how to make patch so this is how looks my corrections in parse

void SaxParser::parse(){

if(!_context) throw internal_error("Parse context not created.");

//_context->sax = & _sax_handler;

memcpy(_context->sax, &_sax_handler, sizeof(xmlSAXHandler));

_context->userData = this;

initialize_context();

xmlParseDocument(_context);

if( (! _context->wellFormed)

&& (! _exception) )

_exception = new parse_error("Document not well-formed");

//release_underlying();

xmlFreeParserCtxt(_context);

_context = 0;

check_for_exception();

}

best regards
 
Thierry Blanchard


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