Open damb opened 3 years ago
References #16.
Interestingly, Boost.Test seems to leak memory with ASan enabled. Here, the reproducer:
#define BOOST_TEST_MODULE test_foo
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test_foo) {
BOOST_TEST_MESSAGE("Boost version: " << BOOST_VERSION);
BOOST_TEST_CHECK(true);
}
which returns
Running 1 test case...
Boost version: 106900
*** No errors detected
=================================================================
==1301184==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 102 byte(s) in 5 object(s) allocated from:
#0 0x7f16c3693067 in operator new(unsigned long) (/lib64/libasan.so.6+0xb2067)
#1 0x7f16c359102f (/lib64/libboost_unit_test_framework.so.1.69.0+0x5202f)
SUMMARY: AddressSanitizer: 102 byte(s) leaked in 5 allocation(s).
when compiled and linked with
-fsanitize=address
and run, afterwards. Of course, this can be suppressed with a corresponding LSan suppression file:
$ cat LSan.supp
leak:libboost_unit_test_framework.so.*
However, this is rather a work around.
gcc
version:
$ g++ --version
g++ (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
libboost_unit_test_framework.so.1.69.0
uname -a
Linux seiscomp-fedora32 5.4.72-gentoo #1 SMP Mon Oct 19 16:07:57 CEST 2020 x86_64 x86_64 x86_64 GNU/Linux`
Note that the test binary is both compiled and run from within a Fedora32 LCX container image on a gentoo host.
It turns out that Valgrind's Memcheck utility detects the issue, too.
In order to detect memory issues as early as possible, it would be good to enable AddressSanitizer when running unittests. The error detector comes with both gcc and clang builtin, anyway.