From: Kefu Chai Date: Thu, 29 May 2025 15:26:06 +0000 (+0800) Subject: rgw/dbstore: free objectmap in DB::Destroy() X-Git-Tag: testing/wip-vshankar-testing-20250610.034655-debug~3^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2e6108d25d6f7926034620f84a4838a856241354;p=ceph-ci.git rgw/dbstore: free objectmap in DB::Destroy() Memory leak was detected by AddressSanitizer in dbstore tests. Objects inserted into a static objectmap were not being properly freed when tests completed without explicitly deleting buckets. The leak occurred because: - Objects were preserved in a static map after insertion - Objects were only freed by DB::objectmapDelete() when deleting the corresponding bucket - In tests, buckets weren't always deleted after insertion, leaving objects allocated ASan rightly pointed this out: ``` Direct leak of 200 byte(s) in 1 object(s) allocated from: #0 0x55c420f5274d in operator new(unsigned long) (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/unittest_dbstore_tests+0x4df74d) (BuildId: c19ed2d2b1ead306fdc59fc311f546a287300010) #1 0x55c42143cfaf in SQLGetBucket::Execute(DoutPrefixProvider const*, rgw::store::DBOpParams*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/rgw/driver/dbstore/sqlite/sqliteDB.cc:1689:11 #2 0x55c42102751c in rgw::store::DB::ProcessOp(DoutPrefixProvider const*, std::basic_string_view>, rgw::store::DBOpParams*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/rgw/driver/dbstore/common/dbstore.cc:251:16 #3 0x55c4210328c9 in rgw::store::DB::get_bucket_info(DoutPrefixProvider const*, std::__cxx11::basic_string, std::allocator> const&, std::__cxx11::basic_string, std::allocator> const&, RGWBucketInfo&, std::map, std::allocator>, ceph::buffer::v15_2_0::list, std::less, std::allocator>>, std::allocator, std::allocator> const, ceph::buffer::v15_2_0::list>>>*, std::chrono::time_point>>*, obj_version*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/rgw/driver/dbstore/common/dbstore.cc:450:9 #4 0x55c421034357 in rgw::store::DB::create_bucket(DoutPrefixProvider const*, std::variant const&, rgw_bucket const&, std::__cxx11::basic_string, std::allocator> const&, rgw_placement_rule const&, std::map, std::allocator>, ceph::buffer::v15_2_0::list, std::less, std::allocator>>, std::allocator, std::allocator> const, ceph::buffer::v15_2_0::list>>> const&, std::optional, std::allocator>> const&, std::optional const&, std::optional>>>, obj_version*, RGWBucketInfo&, optional_yield) /home/jenkins-build/build/workspace/ceph-pull-requests/src/rgw/driver/dbstore/common/dbstore.cc:504:9 #5 0x55c420f6c3ed in DBStoreTest_CreateBucket_Test::TestBody() /home/jenkins-build/build/workspace/ceph-pull-requests/src/rgw/driver/dbstore/tests/dbstore_tests.cc:495:13 #6 0x55c42174fa0d in void testing::internal::HandleSehExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2653:10 #7 0x55c421717f25 in void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2689:14 #8 0x55c4216d4bbd in testing::Test::Run() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2728:5 ``` In this change, we: - Free objectmap entries in DB::Destroy() to ensure cleanup on shutdown - Call DB::Destroy() in DBStoreTest::TearDown() to guarantee cleanup after each test Signed-off-by: Kefu Chai --- diff --git a/src/rgw/driver/dbstore/common/dbstore.cc b/src/rgw/driver/dbstore/common/dbstore.cc index ccd643c851b..687b805c86b 100644 --- a/src/rgw/driver/dbstore/common/dbstore.cc +++ b/src/rgw/driver/dbstore/common/dbstore.cc @@ -82,6 +82,13 @@ int DB::Destroy(const DoutPrefixProvider *dpp) closeDB(dpp); + { + const std::lock_guard lk(mtx); + for (auto& bucket_object : DB::objectmap) { + delete bucket_object.second; + } + objectmap.clear(); + } ldpp_dout(dpp, 20)<<"DB successfully destroyed - name:" \ <