Skip to content

AGDDControl: Fixing a memory leak in AGDDControl/XMLHandler

I noticed the following memory leaks on the AGDDControl/XMLHandler:

33,552 bytes in 2,796 blocks are definitely lost in loss record 94,043 of 95,384
  at 0x4C2AA02: operator new(unsigned long) (vg_replace_malloc.c:344)
  by 0x4138C078: xercesc_3_1::MemoryManagerImpl::allocate(unsigned long) (MemoryManagerImpl.cpp:40)
  by 0x4145ACE3: xercesc_3_1::IconvGNULCPTranscoder::transcode(char const*, xercesc_3_1::MemoryManager*) (IconvGNUTransService.cpp:870)
  by 0x4118F772: XMLHandler::getAttribute(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool&) const (XMLHandler.cxx:47)
  by 0x4118FC18: XMLHandler::getAttributeAsDouble(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool&) const (XMLHandler.cxx:125)
  by 0x4112A5D5: varHandler::ElementHandle() (varHandler.cxx:18)
  by 0x41193551: Handle (XMLHandler.h:24)
  by 0x41193551: XercesParser::elementLoop(xercesc_3_1::DOMNode*) (XercesParser.cxx:202)
  by 0x411937AF: XercesParser::elementLoop(xercesc_3_1::DOMNode*) (XercesParser.cxx:215)
  by 0x411937AF: XercesParser::elementLoop(xercesc_3_1::DOMNode*) (XercesParser.cxx:215)
  by 0x41193852: XercesParser::navigateTree() (XercesParser.cxx:184)
  by 0x4119305E: ParseStringAndNavigate (XercesParser.cxx:145)
  by 0x4119305E: XercesParser::ParseStringAndNavigate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (XercesParser.cxx:142)
  by 0x4117AD93: AGDDController::ParseString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (AGDDController.cxx:134)
  by 0x6407E23A: MuonAGDDTool::construct() (MuonAGDDTool.cxx:104)
  by 0x6407F9EB: MuonAGDDTool::initialize() (MuonAGDDTool.cxx:63)

Apparently each transcode should eventually be followed-up w/ a release. Failing this causes a leak. This MR simply encapsulates transcode in a unique_ptr that has a custom deleter in which we release the buffer. Valgrind seems to agree this works.

cc: @nkoehler

Merge request reports

Loading