From fd5b00d755a9f0136d651609200771d56cbf0f93 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 30 Mar 2024 21:21:25 +0800 Subject: [PATCH] tests: unittest_rocksdb_option: do not leak RocksDBStore before this change, we allocate an instance of `RocksDBStore` with `new`, but we never free it. and LeanSanitizer points this out: ``` Direct leak of 952 byte(s) in 1 object(s) allocated from: #0 0x55f31440bc2d in operator new(unsigned long) (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/unittest_rocksdb_option+0xaebc2d) (BuildId: 81b849dbc41cbc6b05d5e603d9ba8a002dab2d24) #1 0x55f3144132fd in RocksDBOption_simple_Test::TestBody() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/objectstore/TestRocksdbOptionParse.cc:17:22 #2 0x55f3144ecf26 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:2605:10 #3 0x55f3144a4312 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:2641:14 #4 0x55f314453ccc in testing::Test::Run() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2680:5 #5 0x55f314455d02 in testing::TestInfo::Run() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2858:11 #6 0x55f31445733b in testing::TestSuite::Run() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:3012:28 #7 0x55f3144747c8 in testing::internal::UnitTestImpl::RunAllTests() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:5723:44 #8 0x55f3144f5576 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 #9 0x55f3144ab1a2 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 #10 0x55f314473b52 in testing::UnitTest::Run() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:5306:10 #11 0x55f31440f690 in RUN_ALL_TESTS() /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/include/gtest/gtest.h:2486:46 #12 0x55f31440e4c3 in main /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/unit.cc:45:10 #13 0x7f0d32551d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 ``` in this change, we manage the life cycle of `RocksDBStore` using a smart pointer. this should address the leak. Signed-off-by: Kefu Chai --- src/test/objectstore/TestRocksdbOptionParse.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/objectstore/TestRocksdbOptionParse.cc b/src/test/objectstore/TestRocksdbOptionParse.cc index c34ea6bc2361a..986eea8f16ce3 100644 --- a/src/test/objectstore/TestRocksdbOptionParse.cc +++ b/src/test/objectstore/TestRocksdbOptionParse.cc @@ -14,7 +14,7 @@ TEST(RocksDBOption, simple) { rocksdb::Options options; rocksdb::Status status; map kvoptions; - RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, kvoptions, NULL); + auto db = std::make_unique(g_ceph_context, dir, kvoptions, nullptr); string options_string = "" "write_buffer_size=536870912;" "create_if_missing=true;" @@ -48,7 +48,7 @@ TEST(RocksDBOption, interpret) { rocksdb::Options options; rocksdb::Status status; map kvoptions; - RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, kvoptions, NULL); + auto db = std::make_unique(g_ceph_context, dir, kvoptions, nullptr); string options_string = "compact_on_mount = true; compaction_threads=10;flusher_threads=5;"; int r = db->ParseOptionsFromString(options_string, options);