nextsimhub / nextsimdg

neXtSIM_DG : next generation sea-ice model with DG
https://nextsim-dg.readthedocs.io/en/latest/?badge=latest
Apache License 2.0
10 stars 13 forks source link

memory leaks in dynamics #716

Closed Thanduriel closed 1 week ago

Thanduriel commented 1 month ago

With #674 integrated, we now expect dynamic buffers to get freed before the program terminates. However, for the dynamics benchmark valgrind currently still reports some leaks:

==41968== 1,495,136 (248 direct, 1,494,888 indirect) bytes in 1 blocks are definitely lost in loss record 73 of 74
==41968==    at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==41968==    by 0x4A19A64: Nextsim::DynamicsKernel<6, 8>::initialise(Nextsim::ModelArray const&, bool, Nextsim::ModelArray const&) (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x4AF4F34: Nextsim::CGDynamicsKernel<6>::initialise(Nextsim::ModelArray const&, bool, Nextsim::ModelArray const&) (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x4A2A59D: Nextsim::MEVPDynamics::setData(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Nextsim::ModelArray, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Nextsim::ModelArray> > > const&) (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x49E3EC7: Nextsim::PrognosticData::setData(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Nextsim::ModelArray, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Nextsim::ModelArray> > > const&) (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x4999194: Nextsim::Model::configure() (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x10AE07: main (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/nextsim)
==41968== 
==41968== 2,074,384 (256 direct, 2,074,128 indirect) bytes in 1 blocks are definitely lost in loss record 74 of 74
==41968==    at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==41968==    by 0x4AF4F3E: Nextsim::CGDynamicsKernel<6>::initialise(Nextsim::ModelArray const&, bool, Nextsim::ModelArray const&) (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x4A2A59D: Nextsim::MEVPDynamics::setData(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Nextsim::ModelArray, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Nextsim::ModelArray> > > const&) (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x49E3EC7: Nextsim::PrognosticData::setData(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Nextsim::ModelArray, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Nextsim::ModelArray> > > const&) (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x4999194: Nextsim::Model::configure() (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/libnextsimlib.so)
==41968==    by 0x10AE07: main (in /home/thanduriel/Documents/projects/nextsimdg/nextsimdg/build/nextsim)
==41968== 
==41968== LEAK SUMMARY:
==41968==    definitely lost: 512 bytes in 3 blocks
==41968==    indirectly lost: 3,569,016 bytes in 24 blocks
==41968==      possibly lost: 1,186,944 bytes in 21 blocks
==41968==    still reachable: 110,717 bytes in 719 blocks
==41968==         suppressed: 0 bytes in 0 blocks

These should be solved by switching the raw pointers to unique_ptr.