Skip to content

Multithreading: Fix some Memory Leaks

Simon Spannagel requested to merge mt_memleaks into multithreading

This MR fixes some (smaller) memory leaks found while valgrinding the heck out of APSQ MT.

I am still trying to understand why memory allocation grows over time, and e.g. on my laptop with four worker threads blocks > 12GB of RAM after some 100k events. However, Valgrind doesn't bring me any further and the only other relevant leaks I have found I'm not sure how to tackle - or if they are some anyway:

Furthermore, this MR might serve as discussion platform for a few other murky places in the code base.

==60234== 10,144 (32 direct, 10,112 indirect) bytes in 1 blocks are definitely lost in loss record 14,450 of 15,010
==60234==    at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==60234==    by 0xE332E0D: TStorage::ObjectAlloc(unsigned long) (in /opt/root/lib/libCore.so)
==60234==    by 0xE3CC219: TClass::GetCollectionProxy() const (in /opt/root/lib/libCore.so)
==60234==    by 0xCD94923: TTree::BronchExec(char const*, char const*, void*, bool, int, int) (in /opt/root/lib/libTree.so)
==60234==    by 0xCD7E85B: TTree::Bronch(char const*, char const*, void*, int, int) (in /opt/root/lib/libTree.so)
==60234==    by 0x4B9AA1E: allpix::ROOTObjectWriterModule::run(allpix::Event*) (ROOTObjectWriterModule.cpp:167)
==60234==    by 0xD176041: allpix::BufferedModule::flush_buffered_events() (Module.cpp:274)
==60234==    by 0xD176397: allpix::BufferedModule::run_in_order(std::shared_ptr<allpix::Event>) (Module.cpp:223)
==60234==    by 0xD17E039: allpix::ModuleManager::run(std::mersenne_twister_engine<unsigned long, 64ul, 312ul, 156ul, 31ul, 13043109905998158313ul, 29ul, 6148914691236517205ul, 17ul, 8202884508482404352ul, 37ul, 18444473444759240704ul, 43ul, 6364136223846793005ul>&)::{lambda()#3}::operator()() (ModuleManager.cpp:718)
==60234==    by 0xD17E533: __invoke_impl<void, allpix::ModuleManager::run(std::mt19937_64&)::<lambda()>&> (invoke.h:60)
==60234==    by 0xD17E533: __invoke<allpix::ModuleManager::run(std::mt19937_64&)::<lambda()>&> (invoke.h:95)
==60234==    by 0xD17E533: __call<void> (functional:400)
==60234==    by 0xD17E533: operator()<> (functional:484)
==60234==    by 0xD17E533: __invoke_impl<void, std::_Bind<allpix::ModuleManager::run(std::mt19937_64&)::<lambda()>()>&> (invoke.h:60)
==60234==    by 0xD17E533: __invoke<std::_Bind<allpix::ModuleManager::run(std::mt19937_64&)::<lambda()>()>&> (invoke.h:95)
==60234==    by 0xD17E533: operator() (future:1421)
==60234==    by 0xD17E533: operator() (future:1362)
==60234==    by 0xD17E533: std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> (), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_state<std::_Bind<allpix::ModuleManager::run(std::mersenne_twister_engine<unsigned long, 64ul, 312ul, 156ul, 31ul, 13043109905998158313ul, 29ul, 6148914691236517205ul, 17ul, 8202884508482404352ul, 37ul, 18444473444759240704ul, 43ul, 6364136223846793005ul>&)::{lambda()#3} ()>, std::allocator<int>, void ()>::_M_run()::{lambda()#1}, void> >::_M_invoke(std::_Any_data const&) (std_function.h:286)
==60234==    by 0xD188B9C: operator() (std_function.h:688)
==60234==    by 0xD188B9C: std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*) (future:561)
==60234==    by 0xE60547E: __pthread_once_slow (pthread_once.c:116)

==60234== 10,144 (32 direct, 10,112 indirect) bytes in 1 blocks are definitely lost in loss record 14,451 of 15,010
==60234==    at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==60234==    by 0xE332E0D: TStorage::ObjectAlloc(unsigned long) (in /opt/root/lib/libCore.so)
==60234==    by 0xE3CC219: TClass::GetCollectionProxy() const (in /opt/root/lib/libCore.so)
==60234==    by 0xDC89D5C: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) (in /opt/root/lib/libRIO.so)
==60234==    by 0xDAE11A3: TStreamerInfoActions::GenericWriteAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) (in /opt/root/lib/libRIO.so)
==60234==    by 0xDA185C4: TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (in /opt/root/lib/libRIO.so)
==60234==    by 0xCD184C9: TBranch::FillImpl(ROOT::Internal::TBranchIMTHelper*) [clone .part.0] (in /opt/root/lib/libTree.so)
==60234==    by 0xCD25FDA: TBranchElement::FillImpl(ROOT::Internal::TBranchIMTHelper*) (in /opt/root/lib/libTree.so)
==60234==    by 0xCD91F65: TTree::Fill() (in /opt/root/lib/libTree.so)
==60234==    by 0x4B99B64: allpix::ROOTObjectWriterModule::run(allpix::Event*) (ROOTObjectWriterModule.cpp:204)
==60234==    by 0xD176041: allpix::BufferedModule::flush_buffered_events() (Module.cpp:274)
==60234==    by 0xD176397: allpix::BufferedModule::run_in_order(std::shared_ptr<allpix::Event>) (Module.cpp:223)
==60234== 

Merge request reports