diff options
author | Yao Zongyou <yaozongyou@vip.qq.com> | 2017-12-25 04:32:54 +0100 |
---|---|---|
committer | Yao Zongyou <yaozongyou@vip.qq.com> | 2017-12-25 04:32:54 +0100 |
commit | 045a9fde9e74d4d9253c1d8061cf12cf790c4f4f (patch) | |
tree | 3ac839855418e862e94721beb2976fe7805ad5aa | |
parent | Merge pull request #19580 from cbodley/wip-22473 (diff) | |
download | ceph-045a9fde9e74d4d9253c1d8061cf12cf790c4f4f.tar.xz ceph-045a9fde9e74d4d9253c1d8061cf12cf790c4f4f.zip |
test: fix unittest memory leak to make valgrind silence
Signed-off-by: Yao Zongyou <yaozongyou@vip.qq.com>
-rw-r--r-- | src/test/admin_socket.cc | 36 | ||||
-rw-r--r-- | src/test/bufferlist.cc | 2 | ||||
-rw-r--r-- | src/test/common/test_bloom_filter.cc | 6 | ||||
-rw-r--r-- | src/test/common/test_crc32c.cc | 4 | ||||
-rw-r--r-- | src/test/compressor/test_compression.cc | 2 | ||||
-rw-r--r-- | src/test/erasure-code/TestErasureCodeExample.cc | 2 | ||||
-rw-r--r-- | src/test/erasure-code/TestErasureCodeIsa.cc | 2 | ||||
-rw-r--r-- | src/test/erasure-code/TestErasureCodeJerasure.cc | 2 | ||||
-rw-r--r-- | src/test/erasure-code/TestErasureCodeShec.cc | 3 | ||||
-rw-r--r-- | src/test/objectstore/BitAllocator_test.cc | 65 | ||||
-rw-r--r-- | src/test/objectstore/test_bluefs.cc | 26 |
11 files changed, 75 insertions, 75 deletions
diff --git a/src/test/admin_socket.cc b/src/test/admin_socket.cc index 2949400f84c..096893e0946 100644 --- a/src/test/admin_socket.cc +++ b/src/test/admin_socket.cc @@ -45,15 +45,13 @@ public: }; TEST(AdminSocket, Teardown) { - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); AdminSocketTest asoct(asokc.get()); ASSERT_EQ(true, asoct.shutdown()); } TEST(AdminSocket, TeardownSetup) { - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); AdminSocketTest asoct(asokc.get()); ASSERT_EQ(true, asoct.shutdown()); ASSERT_EQ(true, asoct.init(get_rand_socket_path())); @@ -61,8 +59,7 @@ TEST(AdminSocket, TeardownSetup) { } TEST(AdminSocket, SendHelp) { - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); AdminSocketTest asoct(asokc.get()); ASSERT_EQ(true, asoct.shutdown()); ASSERT_EQ(true, asoct.init(get_rand_socket_path())); @@ -93,8 +90,7 @@ TEST(AdminSocket, SendHelp) { } TEST(AdminSocket, SendNoOp) { - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); AdminSocketTest asoct(asokc.get()); ASSERT_EQ(true, asoct.shutdown()); ASSERT_EQ(true, asoct.init(get_rand_socket_path())); @@ -106,8 +102,7 @@ TEST(AdminSocket, SendNoOp) { } TEST(AdminSocket, SendTooLongRequest) { - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); AdminSocketTest asoct(asokc.get()); ASSERT_EQ(true, asoct.shutdown()); ASSERT_EQ(true, asoct.init(get_rand_socket_path())); @@ -138,13 +133,13 @@ class MyTest : public AdminSocketHook { }; TEST(AdminSocket, RegisterCommand) { - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); + std::unique_ptr<AdminSocketHook> my_test_asok = std::make_unique<MyTest>(); AdminSocketTest asoct(asokc.get()); ASSERT_EQ(true, asoct.shutdown()); ASSERT_EQ(true, asoct.init(get_rand_socket_path())); AdminSocketClient client(get_rand_socket_path()); - ASSERT_EQ(0, asoct.m_asokc->register_command("test", "test", new MyTest(), "")); + ASSERT_EQ(0, asoct.m_asokc->register_command("test", "test", my_test_asok.get(), "")); string result; ASSERT_EQ("", client.do_request("{\"prefix\":\"test\"}", &result)); ASSERT_EQ("test|", result); @@ -170,14 +165,15 @@ class MyTest2 : public AdminSocketHook { }; TEST(AdminSocket, RegisterCommandPrefixes) { - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); + std::unique_ptr<AdminSocketHook> my_test_asok = std::make_unique<MyTest>(); + std::unique_ptr<AdminSocketHook> my_test2_asok = std::make_unique<MyTest2>(); AdminSocketTest asoct(asokc.get()); ASSERT_EQ(true, asoct.shutdown()); ASSERT_EQ(true, asoct.init(get_rand_socket_path())); AdminSocketClient client(get_rand_socket_path()); - ASSERT_EQ(0, asoct.m_asokc->register_command("test", "test name=args,type=CephString,n=N", new MyTest(), "")); - ASSERT_EQ(0, asoct.m_asokc->register_command("test command", "test command name=args,type=CephString,n=N", new MyTest2(), "")); + ASSERT_EQ(0, asoct.m_asokc->register_command("test", "test name=args,type=CephString,n=N", my_test_asok.get(), "")); + ASSERT_EQ(0, asoct.m_asokc->register_command("test command", "test command name=args,type=CephString,n=N", my_test2_asok.get(), "")); string result; ASSERT_EQ("", client.do_request("{\"prefix\":\"test\"}", &result)); ASSERT_EQ("test|", result); @@ -213,8 +209,7 @@ public: TEST(AdminSocketClient, Ping) { string path = get_rand_socket_path(); - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); AdminSocketClient client(path); // no socket { @@ -267,8 +262,7 @@ TEST(AdminSocketClient, Ping) { TEST(AdminSocket, bind_and_listen) { string path = get_rand_socket_path(); - std::unique_ptr<AdminSocket> - asokc(new AdminSocket(g_ceph_context)); + std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context); AdminSocketTest asoct(asokc.get()); // successfull bind diff --git a/src/test/bufferlist.cc b/src/test/bufferlist.cc index 468af934454..4cfc4485fa2 100644 --- a/src/test/bufferlist.cc +++ b/src/test/bufferlist.cc @@ -89,6 +89,7 @@ TEST(Buffer, constructors) { history_alloc_bytes += len; history_alloc_num++; EXPECT_EQ(0, ::memcmp(clone.c_str(), ptr.c_str(), len)); + delete [] str; } // // buffer::create_static @@ -1256,6 +1257,7 @@ TEST(BufferListIterator, copy) { i.seek(0); i.copy(3, copy); EXPECT_EQ(0, ::memcmp(copy, expected, 3)); + free(copy); } // // void buffer::list::iterator::copy_deep(unsigned len, ptr &dest) diff --git a/src/test/common/test_bloom_filter.cc b/src/test/common/test_bloom_filter.cc index 1c6eee78e1e..dc388c3639f 100644 --- a/src/test/common/test_bloom_filter.cc +++ b/src/test/common/test_bloom_filter.cc @@ -177,10 +177,10 @@ TEST(BloomFilter, BinSweep) { int max = total_max / bins; float fpp = total_fpp / bins;//pow(total_fpp, bins); - std::vector<bloom_filter*> ls; + std::vector<std::unique_ptr<bloom_filter>> ls; bufferlist bl; for (int i=0; i<bins; i++) { - ls.push_back(new bloom_filter(max, fpp, i)); + ls.push_back(std::make_unique<bloom_filter>(max, fpp, i)); for (int j=0; j<max; j++) { ls.back()->insert(10000 * (i+1) + j); } @@ -190,7 +190,7 @@ TEST(BloomFilter, BinSweep) { int hit = 0; int test = max * 100; for (int i=0; i<test; ++i) { - for (std::vector<bloom_filter*>::iterator j = ls.begin(); j != ls.end(); ++j) { + for (std::vector<std::unique_ptr<bloom_filter>>::iterator j = ls.begin(); j != ls.end(); ++j) { if ((*j)->contains(i * 732)) { // note: sequential i does not work here; the intenral int hash is weak!! hit++; break; diff --git a/src/test/common/test_crc32c.cc b/src/test/common/test_crc32c.cc index 7071728bb46..67ec6726369 100644 --- a/src/test/common/test_crc32c.cc +++ b/src/test/common/test_crc32c.cc @@ -31,6 +31,8 @@ TEST(Crc32c, PartialWord) { memset((void *)b, 1, 35); ASSERT_EQ(2715569182u, ceph_crc32c(0, (unsigned char *)a, 5)); ASSERT_EQ(440531800u, ceph_crc32c(0, (unsigned char *)b, 35)); + free((void*)a); + free((void*)b); } TEST(Crc32c, Big) { @@ -39,6 +41,7 @@ TEST(Crc32c, Big) { memset(a, 1, len); ASSERT_EQ(31583199u, ceph_crc32c(0, (unsigned char *)a, len)); ASSERT_EQ(1400919119u, ceph_crc32c(1234, (unsigned char *)a, len)); + free(a); } TEST(Crc32c, Performance) { @@ -92,6 +95,7 @@ TEST(Crc32c, Performance) { ASSERT_EQ(261108528u, val); } #endif + free(a); } diff --git a/src/test/compressor/test_compression.cc b/src/test/compressor/test_compression.cc index 8e5cc3f485b..8eded294534 100644 --- a/src/test/compressor/test_compression.cc +++ b/src/test/compressor/test_compression.cc @@ -248,6 +248,7 @@ void test_compress(CompressorRef compressor, size_t size) int res = compressor->compress(in, out); EXPECT_EQ(res, 0); } + free(data); } void test_decompress(CompressorRef compressor, size_t size) @@ -265,6 +266,7 @@ void test_decompress(CompressorRef compressor, size_t size) int res = compressor->decompress(out, out_dec); EXPECT_EQ(res, 0); } + free(data); } TEST_P(CompressorTest, compress_1024) diff --git a/src/test/erasure-code/TestErasureCodeExample.cc b/src/test/erasure-code/TestErasureCodeExample.cc index a6f88201935..bdf7fbd0053 100644 --- a/src/test/erasure-code/TestErasureCodeExample.cc +++ b/src/test/erasure-code/TestErasureCodeExample.cc @@ -203,7 +203,7 @@ TEST(ErasureCodeExample, decode) TEST(ErasureCodeExample, create_rule) { - CrushWrapper *c = new CrushWrapper; + std::unique_ptr<CrushWrapper> c = std::make_unique<CrushWrapper>(); c->create(); c->set_type_name(2, "root"); c->set_type_name(1, "host"); diff --git a/src/test/erasure-code/TestErasureCodeIsa.cc b/src/test/erasure-code/TestErasureCodeIsa.cc index f38d8360f17..4a288e3ff50 100644 --- a/src/test/erasure-code/TestErasureCodeIsa.cc +++ b/src/test/erasure-code/TestErasureCodeIsa.cc @@ -876,7 +876,7 @@ TEST_F(IsaErasureCodeTest, isa_xor_codec) TEST_F(IsaErasureCodeTest, create_rule) { - CrushWrapper *c = new CrushWrapper; + std::unique_ptr<CrushWrapper> c = std::make_unique<CrushWrapper>(); c->create(); int root_type = 2; c->set_type_name(root_type, "root"); diff --git a/src/test/erasure-code/TestErasureCodeJerasure.cc b/src/test/erasure-code/TestErasureCodeJerasure.cc index efe553565cc..5201b02a38b 100644 --- a/src/test/erasure-code/TestErasureCodeJerasure.cc +++ b/src/test/erasure-code/TestErasureCodeJerasure.cc @@ -279,7 +279,7 @@ TEST(ErasureCodeTest, encode) TEST(ErasureCodeTest, create_rule) { - CrushWrapper *c = new CrushWrapper; + std::unique_ptr<CrushWrapper> c = std::make_unique<CrushWrapper>(); c->create(); int root_type = 2; c->set_type_name(root_type, "root"); diff --git a/src/test/erasure-code/TestErasureCodeShec.cc b/src/test/erasure-code/TestErasureCodeShec.cc index 5ba6d8b1d45..3099a1f67a7 100644 --- a/src/test/erasure-code/TestErasureCodeShec.cc +++ b/src/test/erasure-code/TestErasureCodeShec.cc @@ -947,6 +947,7 @@ TEST(ErasureCodeShec, init2_5) delete shec; delete profile; + delete profile2; } TEST(ErasureCodeShec, minimum_to_decode_8) @@ -2717,7 +2718,7 @@ void* thread3(void* pParam) { ErasureCodeShec* shec = (ErasureCodeShec*) pParam; - CrushWrapper *crush = new CrushWrapper; + std::unique_ptr<CrushWrapper> crush = std::make_unique<CrushWrapper>(); crush->create(); crush->set_type_name(2, "root"); crush->set_type_name(1, "host"); diff --git a/src/test/objectstore/BitAllocator_test.cc b/src/test/objectstore/BitAllocator_test.cc index 14041b6c2af..3b8168ef34c 100644 --- a/src/test/objectstore/BitAllocator_test.cc +++ b/src/test/objectstore/BitAllocator_test.cc @@ -276,7 +276,7 @@ TEST(BitAllocator, test_zone_alloc) int total_blocks = 1024; int64_t allocated = 0; - BitMapZone *zone = new BitMapZone(g_ceph_context, total_blocks, 0); + std::unique_ptr<BitMapZone> zone = std::make_unique<BitMapZone>(g_ceph_context, total_blocks, 0); // Allocate all blocks and see that it is allocating in order. bool lock = zone->lock_excl_try(); @@ -284,22 +284,22 @@ TEST(BitAllocator, test_zone_alloc) int64_t blk_size = 1024; AllocExtentVector extents; - ExtentList *block_list = new ExtentList(&extents, blk_size); - allocated = zone->alloc_blocks_dis(zone->size() / 2, 1, 0, 0, block_list); + std::unique_ptr<ExtentList> block_list = std::make_unique<ExtentList>(&extents, blk_size); + allocated = zone->alloc_blocks_dis(zone->size() / 2, 1, 0, 0, block_list.get()); bmap_test_assert(allocated == zone->size() / 2); { int64_t blk_size = 1024; AllocExtentVector extents; - ExtentList *block_list = new ExtentList(&extents, blk_size); + std::unique_ptr<ExtentList> block_list = std::make_unique<ExtentList>(&extents, blk_size); - zone = new BitMapZone(g_ceph_context, total_blocks, 0); + zone = std::make_unique<BitMapZone>(g_ceph_context, total_blocks, 0); lock = zone->lock_excl_try(); bmap_test_assert(lock); for (int i = 0; i < zone->size(); i += 4) { block_list->reset(); - allocated = zone->alloc_blocks_dis(1, 1, i, 0, block_list); + allocated = zone->alloc_blocks_dis(1, 1, i, 0, block_list.get()); bmap_test_assert(allocated == 1); EXPECT_EQ(extents[0].offset, (uint64_t) i * blk_size); } @@ -320,7 +320,7 @@ TEST(BitAllocator, test_zone_alloc) for (int64_t j = 0; j <= BmapEntry::size(); j = 1 << j) { extents.clear(); ExtentList *block_list = new ExtentList(&extents, blk_size); - zone = new BitMapZone(g_ceph_context, total_blocks, 0); + zone = std::make_unique<BitMapZone>(g_ceph_context, total_blocks, 0); lock = zone->lock_excl_try(); bmap_test_assert(lock); @@ -330,7 +330,6 @@ TEST(BitAllocator, test_zone_alloc) bmap_test_assert(allocated == need_blks); bmap_test_assert(extents[0].offset == (uint64_t) j); delete block_list; - delete zone; } } @@ -338,7 +337,7 @@ TEST(BitAllocator, test_zone_alloc) { extents.clear(); ExtentList *block_list = new ExtentList(&extents, blk_size); - zone = new BitMapZone(g_ceph_context, total_blocks, 0); + zone = std::make_unique<BitMapZone>(g_ceph_context, total_blocks, 0); lock = zone->lock_excl_try(); for (int iter = 1; iter < 5; iter++) { @@ -364,35 +363,33 @@ TEST(BitAllocator, test_zone_alloc) } } delete block_list; - delete zone; } { extents.clear(); - ExtentList *block_list = new ExtentList(&extents, blk_size); - zone = new BitMapZone(g_ceph_context, total_blocks, 0); + std::unique_ptr<ExtentList> block_list(new ExtentList(&extents, blk_size)); + zone = std::make_unique<BitMapZone>(g_ceph_context, total_blocks, 0); lock = zone->lock_excl_try(); bmap_test_assert(lock); block_list->reset(); - allocated = zone->alloc_blocks_dis(total_blocks + 1, total_blocks + 1, 0, 1024, block_list); + allocated = zone->alloc_blocks_dis(total_blocks + 1, total_blocks + 1, 0, 1024, block_list.get()); bmap_test_assert(allocated == 0); block_list->reset(); - allocated = zone->alloc_blocks_dis(total_blocks, total_blocks, 1, 1024, block_list); + allocated = zone->alloc_blocks_dis(total_blocks, total_blocks, 1, 1024, block_list.get()); bmap_test_assert(allocated == 0); block_list->reset(); - allocated = zone->alloc_blocks_dis(total_blocks, total_blocks, 0, 0, block_list); + allocated = zone->alloc_blocks_dis(total_blocks, total_blocks, 0, 0, block_list.get()); bmap_test_assert(allocated == total_blocks); bmap_test_assert(extents[0].offset == 0); zone->free_blocks(extents[0].offset, allocated); - delete block_list; extents.clear(); - block_list = new ExtentList(&extents, blk_size, total_blocks / 4 * blk_size); - allocated = zone->alloc_blocks_dis(total_blocks, total_blocks / 4, 0, 0, block_list); + block_list = std::make_unique<ExtentList>(&extents, blk_size, total_blocks / 4 * blk_size); + allocated = zone->alloc_blocks_dis(total_blocks, total_blocks / 4, 0, 0, block_list.get()); bmap_test_assert(allocated == total_blocks); for (int i = 0; i < 4; i++) { bmap_test_assert(extents[i].offset == (uint64_t) i * (total_blocks / 4)); @@ -429,11 +426,11 @@ TEST(BitAllocator, test_bmap_alloc) for (int64_t j = 0; alloc_size <= total_blocks; j++) { int64_t blk_size = 1024; AllocExtentVector extents; - ExtentList *block_list = new ExtentList(&extents, blk_size, alloc_size); + std::unique_ptr<ExtentList> block_list = std::make_unique<ExtentList>(&extents, blk_size, alloc_size); for (int64_t i = 0; i < total_blocks; i += alloc_size) { bmap_test_assert(alloc->reserve_blocks(alloc_size) == true); allocated = alloc->alloc_blocks_dis_res(alloc_size, std::min(alloc_size, zone_size), - 0, block_list); + 0, block_list.get()); bmap_test_assert(alloc_size == allocated); bmap_test_assert(block_list->get_extent_count() == (alloc_size > zone_size? alloc_size / zone_size: 1)); @@ -493,10 +490,10 @@ bool alloc_extents_max_block(BitAllocator *alloc, int64_t count = 0; AllocExtentVector extents; - ExtentList *block_list = new ExtentList(&extents, blk_size, max_alloc); + std::unique_ptr<ExtentList> block_list = std::make_unique<ExtentList>(&extents, blk_size, max_alloc); EXPECT_EQ(alloc->reserve_blocks(total_alloc), true); - allocated = alloc->alloc_blocks_dis_res(total_alloc, blk_size, 0, block_list); + allocated = alloc->alloc_blocks_dis_res(total_alloc, blk_size, 0, block_list.get()); EXPECT_EQ(allocated, total_alloc); max_alloc = total_alloc > max_alloc? max_alloc: total_alloc; @@ -518,13 +515,13 @@ TEST(BitAllocator, test_bmap_alloc2) { int64_t total_blocks = 1024 * 4; int64_t zone_size = 1024; - BitAllocator *alloc = new BitAllocator(g_ceph_context, total_blocks, + std::unique_ptr<BitAllocator> alloc = std::make_unique<BitAllocator>(g_ceph_context, total_blocks, zone_size, CONCURRENT); - alloc_extents_max_block(alloc, 1, 16); - alloc_extents_max_block(alloc, 4, 16); - alloc_extents_max_block(alloc, 16, 16); - alloc_extents_max_block(alloc, 32, 16); + alloc_extents_max_block(alloc.get(), 1, 16); + alloc_extents_max_block(alloc.get(), 4, 16); + alloc_extents_max_block(alloc.get(), 16, 16); + alloc_extents_max_block(alloc.get(), 32, 16); } __thread int my_tid; @@ -537,16 +534,16 @@ do_work_dis(BitAllocator *alloc) int64_t num_blocks = alloc->size() / NUM_THREADS; AllocExtentVector extents; - ExtentList *block_list = new ExtentList(&extents, 4096); + std::unique_ptr<ExtentList> block_list = std::make_unique<ExtentList>(&extents, 4096); while (num_iters--) { alloc_assert(alloc->reserve_blocks(num_blocks)); - alloced = alloc->alloc_blocks_dis_res(num_blocks, 1, 0, block_list); + alloced = alloc->alloc_blocks_dis_res(num_blocks, 1, 0, block_list.get()); alloc_assert(alloced == num_blocks); - alloc_assert(alloc->is_allocated_dis(block_list, num_blocks)); - alloc->free_blocks_dis(num_blocks, block_list); - block_list->reset(); + alloc_assert(alloc->is_allocated_dis(block_list.get(), num_blocks)); + alloc->free_blocks_dis(num_blocks, block_list.get()); + block_list.get()->reset(); } } @@ -572,14 +569,14 @@ TEST(BitAllocator, test_bmap_alloc_concurrent) bmap_test_assert(total_blocks <= MAX_BLOCKS); - BitAllocator *alloc = new BitAllocator(g_ceph_context, total_blocks, + std::unique_ptr<BitAllocator> alloc = std::make_unique<BitAllocator>(g_ceph_context, total_blocks, zone_size, CONCURRENT); for (int k = 0; k < 2; k++) { cont = k; printf("Spawning %d threads for parallel test. Mode Cont = %d.....\n", NUM_THREADS, cont); for (int j = 0; j < NUM_THREADS; j++) { - if (pthread_create(&pthreads[j], NULL, worker, alloc)) { + if (pthread_create(&pthreads[j], NULL, worker, alloc.get())) { printf("Unable to create worker thread.\n"); exit(0); } diff --git a/src/test/objectstore/test_bluefs.cc b/src/test/objectstore/test_bluefs.cc index 7dc2e8e6086..0b2f2df7019 100644 --- a/src/test/objectstore/test_bluefs.cc +++ b/src/test/objectstore/test_bluefs.cc @@ -30,11 +30,11 @@ string get_temp_bdev(uint64_t size) return fn; } -char* gen_buffer(uint64_t size) +std::unique_ptr<char[]> gen_buffer(uint64_t size) { - char *buffer = new char[size]; + std::unique_ptr<char[]> buffer = std::make_unique<char[]>(size); boost::random::random_device rand; - rand.generate(buffer, buffer + size); + rand.generate(buffer.get(), buffer.get() + size); return buffer; } @@ -156,8 +156,8 @@ void write_data(BlueFS &fs, uint64_t rationed_bytes) ASSERT_NE(nullptr, h); auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); }); bufferlist bl; - char *buf = gen_buffer(ALLOC_SIZE); - bufferptr bp = buffer::claim_char(ALLOC_SIZE, buf); + std::unique_ptr<char[]> buf = gen_buffer(ALLOC_SIZE); + bufferptr bp = buffer::claim_char(ALLOC_SIZE, buf.get()); bl.push_back(bp); h->append(bl.c_str(), bl.length()); r = fs.fsync(h); @@ -181,8 +181,8 @@ void create_single_file(BlueFS &fs) string file = "testfile"; ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false)); bufferlist bl; - char *buf = gen_buffer(ALLOC_SIZE); - bufferptr bp = buffer::claim_char(ALLOC_SIZE, buf); + std::unique_ptr<char[]> buf = gen_buffer(ALLOC_SIZE); + bufferptr bp = buffer::claim_char(ALLOC_SIZE, buf.get()); bl.push_back(bp); h->append(bl.c_str(), bl.length()); fs.fsync(h); @@ -202,8 +202,8 @@ void write_single_file(BlueFS &fs, uint64_t rationed_bytes) ASSERT_NE(nullptr, h); auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); }); bufferlist bl; - char *buf = gen_buffer(ALLOC_SIZE); - bufferptr bp = buffer::claim_char(ALLOC_SIZE, buf); + std::unique_ptr<char[]> buf = gen_buffer(ALLOC_SIZE); + bufferptr bp = buffer::claim_char(ALLOC_SIZE, buf.get()); bl.push_back(bp); h->append(bl.c_str(), bl.length()); int r = fs.fsync(h); @@ -370,8 +370,8 @@ TEST(BlueFS, test_simple_compaction_sync) { ASSERT_NE(nullptr, h); auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); }); bufferlist bl; - char *buf = gen_buffer(4096); - bufferptr bp = buffer::claim_char(4096, buf); + std::unique_ptr<char[]> buf = gen_buffer(4096); + bufferptr bp = buffer::claim_char(4096, buf.get()); bl.push_back(bp); h->append(bl.c_str(), bl.length()); fs.fsync(h); @@ -423,8 +423,8 @@ TEST(BlueFS, test_simple_compaction_async) { ASSERT_NE(nullptr, h); auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); }); bufferlist bl; - char *buf = gen_buffer(4096); - bufferptr bp = buffer::claim_char(4096, buf); + std::unique_ptr<char[]> buf = gen_buffer(4096); + bufferptr bp = buffer::claim_char(4096, buf.get()); bl.push_back(bp); h->append(bl.c_str(), bl.length()); fs.fsync(h); |