Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

Test results in a memory leak in Catch2?

Open gabyx opened this issue 2 years ago • 1 comments

Running an executable with a simple test (which has no memory leak): Is this a false positive and how to avoid it?

─❯ bin/tests/base-io-tests-dbg
base::Integral::Compute() calledbase::IO::Do() called: 43 , Wuagadugu Private Stringbase::Integral::Compute() calledbase::IO::Do() called: 43 , Wuagadugu Private Stringbase::Integral::Compute() calledbase::IO::Do() called: 76 , Wuagadugu Private Stringbase::Integral::Compute() calledbase::IO::Do() called: 76 , Wuagadugu Private String===============================================================================
All tests passed (9 assertions in 3 test cases)


=================================================================
==47364==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x1012366c0 in wrap_malloc+0xa0 (libclang_rt.asan_osx_dynamic.dylib:x86_64+0x456c0)
    #1 0x100e873fd in __cxa_get_globals+0x3d (libstdc++.6.dylib:x86_64+0xc3fd)
    #2 0x10079ee8d in Catch::Section::~Section() catch.hpp:13174
    #3 0x10079f1e4 in Catch::Section::~Section() catch.hpp:13171
    #4 0x1009b9091 in base::tests::____C_A_T_C_H____T_E_S_T____0() IO.test.cpp:26
    #5 0x1007b5542 in Catch::TestInvokerAsFunction::invoke() const catch.hpp:14321
    #6 0x10079c4f2 in Catch::TestCase::invoke() const catch.hpp:14160
    #7 0x10079c2ee in Catch::RunContext::invokeActiveTestCase() catch.hpp:13020
    #8 0x100795179 in Catch::RunContext::runCurrentTest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) catch.hpp:12993
    #9 0x100792ee6 in Catch::RunContext::runTest(Catch::TestCase const&) catch.hpp:12754
    #10 0x1007a42f0 in Catch::(anonymous namespace)::TestGroup::execute() catch.hpp:13347
    #11 0x1007a2daa in Catch::Session::runInternal() catch.hpp:13553
    #12 0x1007a27b2 in Catch::Session::run() catch.hpp:13509
    #13 0x1007f68bf in int Catch::Session::run<char>(int, char const* const*) catch.hpp:13231
    #14 0x1007f6568 in main main-catch2.test.cpp:32
    #15 0x7fff2037cf3c in start+0x0 (libdyld.dylib:x86_64+0x15f3c)

SUMMARY: AddressSanitizer: 16 byte(s) leaked in 1 allocation(s).

Expected behavior No memory leak?

Reproduction steps

Platform information:

  • OS: macOS 11.6
  • Compiler+version: clang 12, over llvm@12 with brew.
  • Catch version: v2.17.3

gabyx avatar Dec 16 '21 14:12 gabyx

This needs a reproducer.

horenmar avatar Apr 18 '22 08:04 horenmar