Dune::MPIHelper::instance(argc, argv) potentially causes memory leak (AdressSanitizer)
I'm considering a simple (almost empty) main file:
int main(int argc, char** argv) try
{
const auto& mpiHelper = Dune::MPIHelper::instance(argc, argv);
return 0;
}
I'm using clang 10.0.0-4ubuntu1
with -fsanitize=address -fno-omit-frame-pointer
and debug opts
and get this warning:
==80306==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 6848 byte(s) in 3 object(s) allocated from:
#0 0x4972bd in malloc (/home/kilian/Code/Dumux/dumux/build-clang-debug/test/material/fluidmatrixinteractions/porenetwork/test_material_2p_porenetwork+0x4972bd)
#1 0x7f6cf8bc8702 in opal_free_list_grow_st (/lib/x86_64-linux-gnu/libopen-pal.so.40+0x1f702)
....
.... and so on ...
From my experience, AdressSanitizer only rarely yields false positives.
Removing the line Dune::MPIHelper::instance(argc, argv);
from the above example fixes the potential leak.
Somehow the creation of the MPIHelper singleton causes the problem.
DUNE_EXPORT static MPIHelper& instance(int& argc, char**& argv)
{
// create singleton instance
static MPIHelper singleton (argc, argv);
return singleton;
}
More precisly, commenting out
static int is_initialized = MPI_Init(&argc, &argv);
the MPIHelper's ctor removes the warning.
Seems to be a known OpenMPI Bug: https://stackoverflow.com/questions/52096355/leaksanitizer-finds-leak-in-simple-mpi-program
Edited by Kilian Weishaupt