c++memory-leaksxerces-c

XercesDOMParser memory leak in parse function


I have a memory leak using XercesDomParser with following code sample:

//setup parser
auto dom_parser_ = std::make_unique<xercesc::XercesDOMParser>();
dom_parser_->setErrorHandler(error_handler_.get());
dom_parser_->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
dom_parser_->setDoNamespaces(true);
dom_parser_->setDoSchema(true);
dom_parser_->setValidationSchemaFullChecking(true);

//use parser multiple times with different xml param 
xercesc::MemBufInputSource xml_buffer((const XMLByte *)xml,
                                       xml.size(), "dummy");

dom_parser_->parse(xml_buffer);

I was able to find out that function XercesDOMParser::parse leaks memory.

Should I call some function explicitly after each parse call to prevent memory leaks?


Solution

  • I figured out that I should call release on dom document after each parse call:

    dom_parser_->parse(xml_buffer);
    dom_parser_->getDocument()->release();