From f153a7031e56534723c0fc891869902c58acb473 Mon Sep 17 00:00:00 2001 From: haoyixing Date: Sat, 21 Nov 2020 17:09:32 +0800 Subject: [PATCH] test/: use unique_ptr for some formatter whose pointers were not released. some code under test use formatter to output, but Formatter *f was not freed like elsewere. So use unique_ptr to avoid this. Signed-off-by: haoyixing --- src/test/cls_cas/test_cls_cas.cc | 2 +- src/test/objectstore/store_test.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/cls_cas/test_cls_cas.cc b/src/test/cls_cas/test_cls_cas.cc index 01db8a32be6..e730f0d128a 100644 --- a/src/test/cls_cas/test_cls_cas.cc +++ b/src/test/cls_cas/test_cls_cas.cc @@ -327,7 +327,7 @@ TEST(chunk_refs_t, size) bufferlist bl2; encode(a, bl2); if (!bl.contents_equal(bl2)) { - Formatter *f = Formatter::create("json-pretty"); + std::unique_ptr f(Formatter::create("json-pretty")); cout << "original:\n"; f->dump_object("refs", r); f->flush(cout); diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 9d372bbafc0..53b2accb1df 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -7716,7 +7716,7 @@ TEST_P(StoreTest, KVDBHistogramTest) { ASSERT_EQ(r, 0); } - Formatter *f = Formatter::create("store_test", "json-pretty", "json-pretty"); + std::unique_ptr f(Formatter::create("store_test", "json-pretty", "json-pretty")); store->generate_db_histogram(f); f->flush(cout); cout << std::endl; @@ -7760,7 +7760,7 @@ TEST_P(StoreTest, KVDBStatsTest) { ASSERT_EQ(r, 0); } - Formatter *f = Formatter::create("store_test", "json-pretty", "json-pretty"); + std::unique_ptr f(Formatter::create("store_test", "json-pretty", "json-pretty")); store->get_db_statistics(f); f->flush(cout); cout << std::endl; @@ -8305,7 +8305,7 @@ TEST_P(StoreTest, BluestoreStatistics) { ASSERT_EQ(static_cast(bl.length()), r); ASSERT_TRUE(bl_eq(bl, readback)); } - Formatter *f = Formatter::create("store_test", "json-pretty", "json-pretty"); + std::unique_ptr f(Formatter::create("store_test", "json-pretty", "json-pretty")); EXPECT_NO_THROW(store->get_db_statistics(f)); f->flush(cout); cout << std::endl; -- 2.39.5