Skip to content

Fix significant memory leak in HltJetBuilderRun3 (follow up !617)

Fixes a significant memory leak in HltJetBuilderRun3. See the leak sanitiser build test

https://lhcb-nightlies.web.cern.ch/logs/tests/nightly/lhcb-sanitizers/594/x86_64-centos7-gcc9-dbg+lsan/Moore/#failures_51

=================================================================
==1225==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 406728 byte(s) in 807 object(s) allocated from:
    #0 0x7f37c0bd2333 in operator new(unsigned long) /build/gcc/build/contrib/gcc-9.2.0/src/gcc/9.2.0/libsanitizer/lsan/lsan_interceptors.cc:222
    #1 0x7f3771f5cb04 in LHCb::Particle::clone() const /workspace/build/LHCb/InstallArea/x86_64-centos7-gcc9-dbg+lsan/include/Event/Particle.h:767
    #2 0x7f3771f5cb04 in LoKi::FastJetMaker::makeJets(std::vector<LHCb::Particle const*, std::allocator<LHCb::Particle const*> > const&, std::vector<LHCb::Particle*, std::allocator<LHCb::Particle*> >&) const /workspace/build/Phys/Phys/LoKiJets/src/LoKiFastJetMaker.cpp:190
    #3 0x7f377235903b in StatusCode IJetMaker::makeJets<__gnu_cxx::__normal_iterator<LHCb::Particle**, std::vector<LHCb::Particle*, std::allocator<LHCb::Particle*> > > >(__gnu_cxx::__normal_iterator<LHCb::Particle**, std::vector<LHCb::Particle*, std::allocator<LHCb::Particle*> > >, __gnu_cxx::__normal_iterator<LHCb::Particle**, std::vector<LHCb::Particle*, std::allocator<LHCb::Particle*> > >, std::vector<LHCb::Particle*, std::allocator<LHCb::Particle*> >&) const /workspace/build/Phys/Phys/DaVinciInterfaces/Kernel/IJetMaker.h:170
    #4 0x7f377235903b in HltJetBuilderRun3::operator()(KeyedContainer<LHCb::Particle, Containers::KeyedObjectManager<Containers::hashmap> > const&) const /workspace/build/Phys/Phys/JetAccessories/src/HltJetBuilderRun3.cpp:140

Caused by the algorithm disregarding the jet makeR API that states callees must take ownership of the vector of jets returned. Code was cloning (for no good reason) returned objects when passing to the output container, and not deleting the originals.

Fix is simply to not clone, and pass ownership of originals directly to output container.

Better long term fix would be to fix jet maker interface to enforce memory management by returning a vector of unique_ptrs to the newly allocated jets.

A few minor cleanups as well along the way.

FYI @rangel

Edited by Rosen Matev

Merge request reports