Skip to content

Commit ac09ac8

Browse files
authored
Merge pull request ceph#56437 from tchaikov/wip-cephcontext-leak-fixes
test: fix the leakages of `CephContext` identified by LeakSanitizer Reviewed-by: Casey Bodley <[email protected]>
2 parents f19765e + e316c2e commit ac09ac8

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/test/common/test_context.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using namespace std;
3030

3131
TEST(CephContext, do_command)
3232
{
33-
CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get();
33+
boost::intrusive_ptr<CephContext> cct{new CephContext(CEPH_ENTITY_TYPE_CLIENT), false};
3434

3535
cct->_conf->cluster = "ceph";
3636

@@ -89,12 +89,11 @@ TEST(CephContext, do_command)
8989
string s(out.c_str(), out.length());
9090
EXPECT_EQ("<config_diff_get><diff><key><default></default><override>" + value + "</override><final>value</final></key><rbd_default_features><default>61</default><final>61</final></rbd_default_features><rbd_qos_exclude_ops><default>0</default><final>0</final></rbd_qos_exclude_ops></diff></config_diff_get>", s);
9191
}
92-
cct->put();
9392
}
9493

9594
TEST(CephContext, experimental_features)
9695
{
97-
CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get();
96+
boost::intrusive_ptr<CephContext> cct{new CephContext(CEPH_ENTITY_TYPE_CLIENT), false};
9897

9998
cct->_conf->cluster = "ceph";
10099

src/test/common/test_fault_injector.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class Fixture : public testing::Test {
4040
protected:
4141
void SetUp() override {
4242
CephInitParameters params(CEPH_ENTITY_TYPE_CLIENT);
43-
cct = common_preinit(params, CODE_ENVIRONMENT_UTILITY,
44-
CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
43+
cct.reset(common_preinit(params, CODE_ENVIRONMENT_UTILITY,
44+
CINIT_FLAG_NO_DEFAULT_CONFIG_FILE),
45+
false);
4546
prefix.emplace(cct.get(), ceph_subsys_context);
4647
}
4748
void TearDown() override {

src/test/common/test_util.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ TEST(util, collect_sys_info)
3131

3232
map<string, string> sys_info;
3333

34-
CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get();
35-
collect_sys_info(&sys_info, cct);
34+
boost::intrusive_ptr<CephContext> cct{new CephContext(CEPH_ENTITY_TYPE_CLIENT), false};
35+
36+
collect_sys_info(&sys_info, cct.get());
3637

3738
ASSERT_TRUE(sys_info.find("distro") != sys_info.end());
3839
ASSERT_TRUE(sys_info.find("distro_description") != sys_info.end());
39-
40-
cct->put();
4140
}
41+
4242
#endif

src/test/test_ipaddr.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ TEST(pick_address, find_ip_in_subnet_list)
703703
ipv4(&a_two, "10.2.1.123");
704704
ipv6(&a_three, "2001:1234:5678:90ab::cdef");
705705

706-
boost::intrusive_ptr<CephContext> cct = new CephContext(CEPH_ENTITY_TYPE_OSD);
706+
boost::intrusive_ptr<CephContext> cct{new CephContext(CEPH_ENTITY_TYPE_OSD), false};
707707

708708
// match by network
709709
result = find_ip_in_subnet_list(

0 commit comments

Comments
 (0)