Skip to content

Destructor failing while calling derived class function #2722

Closed
@pitiwari

Description

@pitiwari

Found this issue while trying to Create CounterImpl class in envoy/source/common/stats/stats_impl.h .Need some help in fixing it

Title: Destructor failing while calling the derived class function

Description:
Found this issue while trying to Create CounterImpl class in envoy/source/common/stats/stats_impl.h. CounterImpl destructor is calling alloc of the derived class since base class RawStatDataAllocator is pure virtual class but by the time we reach destructor of the base class derived class reference is already lost so we cannot call alloc from the destructor.

Below is how i was creating object

Stats::HeapRawStatDataAllocator alloc_;
Stats::RawStatData *data = alloc_.alloc(name);
Stats::CounterSharedPtr c1(new Stats::CounterImpl(*data, alloc_, std::string(name),std::move(tags)));

I am in the middle of changing HeapRawStatDataAllocator destructor to deallocate the memory which was allocated by alloc but getting segmentation fault via tcmalloc. Below is the back trace

Program received signal SIGSEGV, Segmentation fault.
tcmalloc::SLL_PopRange (end=, start=, N=23, head=0x17ceda0) at src/linked_list.h:88
88 src/linked_list.h: No such file or directory.
(gdb) bt
#0 tcmalloc::SLL_PopRange (end=, start=, N=23, head=0x17ceda0) at src/linked_list.h:88
#1 tcmalloc::ThreadCache::FreeList::PopRange (end=, start=, N=23, this=0x17ceda0) at src/thread_cache.h:238
#2 tcmalloc::ThreadCache::ReleaseToCentralCache (this=this@entry=0x17cec40, src=src@entry=0x17ceda0, cl=cl@entry=11, N=23) at src/thread_cache.cc:200
#3 0x0000000000f314e7 in tcmalloc::ThreadCache::Scavenge (this=0x17cec40) at src/thread_cache.cc:218
#4 0x000000000045e6fd in Envoy::Server::AdminFilterTest_Trailers_Test::~AdminFilterTest_Trailers_Test (this=0x2178000, _in_chrg=) at test/server/http/admin_test.cc:56
#5 0x0000000000ee9d58 in testing::Test::DeleteSelf
(this=0x2178000) at external/com_google_googletest/googletest/include/gtest/gtest.h:453
#6 0x0000000000ef3135 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void> (object=0x2178000,
method=(void (testing::Test::)(testing::Test * const)) 0xee9d2e testing::Test::DeleteSelf_(), location=0x10cc4e7 "the test fixture's destructor")
at external/com_google_googletest/googletest/src/gtest.cc:2401
#7 0x0000000000eef221 in testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void> (object=0x2178000,
method=(void (testing::Test::
)(testing::Test * const)) 0xee9d2e testing::Test::DeleteSelf_(), location=0x10cc4e7 "the test fixture's destructor")
at external/com_google_googletest/googletest/src/gtest.cc:2437
#8 0x0000000000edf31f in testing::TestInfo::Run (this=0x1f90d80) at external/com_google_googletest/googletest/src/gtest.cc:2661
#9 0x0000000000edf927 in testing::TestCase::Run (this=0x1f92100) at external/com_google_googletest/googletest/src/gtest.cc:2773
#10 0x0000000000ee6a53 in testing::internal::UnitTestImpl::RunAllTests (this=0x1f82000) at external/com_google_googletest/googletest/src/gtest.cc:4673
#11 0x0000000000ef3e5d in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x1f82000,
method=(bool (testing::internal::UnitTestImpl::)(testing::internal::UnitTestImpl * const)) 0xee6758 testing::internal::UnitTestImpl::RunAllTests(),
location=0x10ccb90 "auxiliary test code (environments or event listeners)") at external/com_google_googletest/googletest/src/gtest.cc:2401
#12 0x0000000000eefe1b in testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x1f82000,
method=(bool (testing::internal::UnitTestImpl::
)(testing::internal::UnitTestImpl * const)) 0xee6758 testing::internal::UnitTestImpl::RunAllTests(),
location=0x10ccb90 "auxiliary test code (environments or event listeners)") at external/com_google_googletest/googletest/src/gtest.cc:2437
#13 0x0000000000ee55e3 in testing::UnitTest::Run (this=0x15bff40 testing::UnitTest::GetInstance()::instance) at external/com_google_googletest/googletest/src/gtest.cc:4281
#14 0x00000000009b82cc in RUN_ALL_TESTS () at external/com_google_googletest/googletest/include/gtest/gtest.h:2237
#15 0x00000000009b845e in Envoy::TestRunner::RunTests (argc=1, argv=0x7fffffffda68) at ./test/test_runner.h:33
#16 0x00000000009b7450 in main (argc=2, argv=0x7fffffffda68) at test/main.cc:35

Desired Behaviour:
No segmentation fault and memory leak.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestions that are neither investigations, bugs, nor enhancements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions