googletest icon indicating copy to clipboard operation
googletest copied to clipboard

llvm-15 address sanitiser reports memory leak on exit

Open IanCollins opened this issue 3 years ago • 0 comments

Describe the bug

The stack trace says it all...

Direct leak of 8 byte(s) in 1 object(s) allocated from:

#0 0x55cde700951d in operator new(unsigned long) (/build/built/linux/debug_asan/tests/SlowTests+0x197d51d) (BuildId: 5481b2fd59f45706447f0ea44f5af0db0c3788b7)

#1 0x55cde8d2dff4 in testing::internal::UnitTestImpl::UnitTestImpl(testing::UnitTest*) /tmp/../thirdparty/googletest-release-1.10.0/googletest/src/gtest.cc:5025:40

#2 0x55cde8d2d39c in testing::UnitTest::UnitTest() /tmp/../thirdparty/googletest-release-1.10.0/googletest/src/gtest.cc:4974:15

#3 0x55cde8cf30f5 in testing::UnitTest::GetInstance() /tmp/../thirdparty/googletest-release-1.10.0/googletest/src/gtest.cc:4619:19

#4 0x55cde8d4bcf8 in testing::internal::GetUnitTestImpl() /tmp/../thirdparty/googletest-release-1.10.0/googletest/src/gtest-internal-inl.h:951:10

#5 0x55cde8d0ea5a in testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void ()(), void ()(), testing::internal::TestFactoryBase*) /tmp/../thirdparty/googletest-release-1.10.0/googletest/src/gtest.cc:2589:3

The code in question is: listeners()->SetDefaultResultPrinter(new PrettyUnitTestResultPrinter);

The PrettyUnitTestResultPrinter object leaks.

A simple fix is: static PrettyUnitTestResultPrinter pp; listeners()->SetDefaultResultPrinter(&pp);

Steps to reproduce the bug

Build an example using clang-15 using compile and link option -fsanitize=address.

Does the bug persist in the most recent commit?

Yes, the line number shifts to 5555

What operating system and version are you using?

Ubunto 20.04 & 22.04.

What compiler and version are you using?

Ubuntu clang version 15.0.4-++20221026063355+db68723804fd-1~exp1~20221026063432.84 Target: x86_64-pc-linux-gnu Thread model: posix

What build system are you using?

Build with premake+ninja.

Additional context

IanCollins avatar Oct 29 '22 02:10 IanCollins