From f04bc795893a222be61295de18e43a690f5910cb Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 2 Apr 2024 14:51:35 +0800 Subject: [PATCH] test/osd/hitset: free allocated HitSet we allocate a hitset without freeing it in this test, and LeakSanitizer points this out ``` Direct leak of 16 byte(s) in 1 object(s) allocated from: #0 0x557a0841a9dd in operator new(unsigned long) (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/unittest_hitset+0x1ae9dd) (BuildId: ad9be2b52b3d6fb1a567b262c3becaab6373e88d) #1 0x557a0843b98e in ExplicitHashHitSetTest::ExplicitHashHitSetTest() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/osd/hitset.cc:128:46 #2 0x557a0843b918 in ExplicitHashHitSetTest_Construct_Test::ExplicitHashHitSetTest_Construct_Test() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/osd/hitset.cc:133:1 #3 0x557a0843b8cb in testing::internal::TestFactoryImpl::CreateTest() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/include/gtest/internal/gtest-internal.h:472:44 #4 0x557a08532406 in testing::Test* testing::internal::HandleSehExceptionsInMethodIfSupported(testing::internal::TestFactoryBase*, testing::Test* (testing::internal::TestFactoryBase::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2605:10 #5 0x557a084eb892 in testing::Test* testing::internal::HandleExceptionsInMethodIfSupported(testing::internal::TestFactoryBase*, testing::Test* (testing::internal::TestFactoryBase::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2641:14 #6 0x557a0849dd55 in testing::TestInfo::Run() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2848:22 #7 0x557a0849f3bb in testing::TestSuite::Run() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:3012:28 #8 0x557a084bc848 in testing::internal::UnitTestImpl::RunAllTests() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:5723:44 #9 0x557a0853a6d6 in bool testing::internal::HandleSehExceptionsInMethodIfSupported(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2605:10 #10 0x557a084f1222 in bool testing::internal::HandleExceptionsInMethodIfSupported(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2641:14 #11 0x557a084bbbd2 in testing::UnitTest::Run() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:5306:10 #12 0x557a08441c10 in RUN_ALL_TESTS() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/include/gtest/gtest.h:2486:46 #13 0x557a08441ba1 in main /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googlemock/src/gmock_main.cc:70:10 #14 0x7faa493d6d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 ``` in this change, we just free it in the dtor. this should address the warning from the sanitizer. Signed-off-by: Kefu Chai --- src/test/osd/hitset.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/osd/hitset.cc b/src/test/osd/hitset.cc index 6234bdaba233f..41267ea4c6e18 100644 --- a/src/test/osd/hitset.cc +++ b/src/test/osd/hitset.cc @@ -15,10 +15,14 @@ #include class HitSetTestStrap { -public: +protected: HitSet *hitset; +public: explicit HitSetTestStrap(HitSet *h) : hitset(h) {} + ~HitSetTestStrap() { + delete hitset; + } void fill(unsigned count) { char buf[50];