From 2ee77b8bd62df3d202b2dbe28a4609bcde58e6fc Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 25 Mar 2024 22:56:28 +0800 Subject: [PATCH] test/rgw/test_rgw_iam_policy: do not increase ref when creating intrusive_ptr before this change, we increment the refcount when constructing `cct` instrusive_ptr, but nobody owns this smart pointer. also, `CephContext` 's constructor set its refcount to 1. so, when the test finishes, the refcount is 1, and this leads to a leakage of the `CephContext` instance. and LeakSanitizer points this out: ``` Indirect leak of 10880000 byte(s) in 1 object(s) allocated from: #0 0xaaaac359c7c8 in operator new(unsigned long) (/home/jenkins-build/build/workspace/ceph-pull-requests-arm64/build/bin/unittest_rgw_iam_policy+0x211c7c8) (BuildId: 060fadb10da261b52fd5757c7b1e9812d34542f1) #1 0xffff96f764e4 in __gnu_cxx::new_allocator::allocate(unsigned long, void const*) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/ext/new_allocator.h:127:27 #2 0xffff96f757cc in std::allocator::allocate(unsigned long) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/allocator.h:185:32 #3 0xffff96f757cc in boost::circular_buffer >::allocate(unsigned long) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/build/boost/include/boost/circular_buffer/base.hpp:2396:39 #4 0xffff96f75500 in boost::circular_buffer >::initialize_buffer(unsigned long) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/build/boost/include/boost/circular_buffer/base.hpp:2494:18 #5 0xffff96f6ec4c in boost::circular_buffer >::circular_buffer(unsigned long, std::allocator const&) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/build/boost/include/boost/circular_buffer/base.hpp:1039:9 #6 0xffff96f63528 in ceph::logging::Log::Log(ceph::logging::SubsystemMap const*) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/log/Log.cc:53:5 #7 0xffff96045300 in ceph::common::CephContext::CephContext(unsigned int, ceph::common::CephContext::create_options const&) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/common/ceph_context.cc:729:16 #8 0xffff960446ec in ceph::common::CephContext::CephContext(unsigned int, code_environment_t, int) /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/common/ceph_context.cc:697:5 #9 0xaaaac3629238 in IPPolicyTest::IPPolicyTest() /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/test/rgw/test_rgw_iam_policy.cc:864:15 #10 0xaaaac3628da0 in IPPolicyTest_MaskedIPOperations_Test::IPPolicyTest_MaskedIPOperations_Test() /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/test/rgw/test_rgw_iam_policy.cc:869:1 #11 0xaaaac3628d3c in testing::internal::TestFactoryImpl::CreateTest() /home/jenkins-build/build/workspace/ceph-pull-requests-arm64/src/googletest/googletest/include/gtest/internal/gtest-internal.h:472:44 ``` so, in this change, we do not increase the refcount when creating cct. Signed-off-by: Kefu Chai --- src/test/rgw/test_rgw_iam_policy.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/rgw/test_rgw_iam_policy.cc b/src/test/rgw/test_rgw_iam_policy.cc index dac4d2cef3889..d65ef9185e1ef 100644 --- a/src/test/rgw/test_rgw_iam_policy.cc +++ b/src/test/rgw/test_rgw_iam_policy.cc @@ -159,7 +159,7 @@ class PolicyTest : public ::testing::Test { static string example7; public: PolicyTest() { - cct = new CephContext(CEPH_ENTITY_TYPE_CLIENT); + cct.reset(new CephContext(CEPH_ENTITY_TYPE_CLIENT), false); } }; @@ -857,7 +857,7 @@ class IPPolicyTest : public ::testing::Test { const rgw::IAM::MaskedIP allowedIPv6Range = { true, rgw::IAM::Address("00100000000000010000110110111000100001011010001100000000000000000000000000000000100010100010111000000011011100000111001100110000"), 124 }; public: IPPolicyTest() { - cct = new CephContext(CEPH_ENTITY_TYPE_CLIENT); + cct.reset(new CephContext(CEPH_ENTITY_TYPE_CLIENT), false); } }; const string IPPolicyTest::arbitrary_tenant = "arbitrary_tenant";