Skip to content

Commit c449473

Browse files
committed
test/erasure-code: fix memory leak in ErasureCodePlugin.parity_delta_write
Fix 4KB memory leak in ErasureCodePlugin_parity_delta_write_Test caused by unmanaged raw buffer allocation. The test was allocating a 4096-byte raw buffer to replace shard 4 for delta encoding validation, but the buffer::ptr constructed from the raw pointer did not manage the buffer's lifecycle. Detected by AddressSanitizer: ``` Direct leak of 4096 byte(s) in 1 object(s) allocated from: #0 0x7fb73a720e15 in malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:67 ceph#1 0x5562f4062ccc in ErasureCodePlugin_parity_delta_write_Test::TestBody() /home/kefu/dev/ceph/src/test/erasure-code/TestErasureCodePluginJerasure.cc:122 ceph#2 0x5562f41081a1 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/kefu/dev/ceph/src/googletest/googletest/src/gtest.cc:2653 ceph#3 0x5562f40f3004 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/kefu/dev/ceph/src/googletest/googletest/src/gtest.cc:2689 ceph#4 0x5562f409cbba in testing::Test::Run() /home/kefu/dev/ceph/src/googletest/googletest/src/gtest.cc:2728``` ``` In this change, we replace raw pointer allocation with create_bufferptr() to ensure proper memory management by buffer::ptr. Signed-off-by: Kefu Chai <[email protected]>
1 parent 3fb436a commit c449473

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/test/erasure-code/TestErasureCodePluginJerasure.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ TEST(ErasureCodePlugin, parity_delta_write) {
118118
ASSERT_EQ(*(uint32_t*)coding[s].c_str(), *(uint32_t*)coding2[s].c_str());
119119
}
120120

121-
data.erase(shard_id_t(4));
122-
data.emplace(shard_id_t(4), (char*)malloc(4096), 4096);
121+
data[shard_id_t(4)] = create_bufferptr(4096);
123122
shard_id_set want;
124123
want.insert_range(shard_id_t(0), 5);
125124
decode_in[shard_id_t(0)] = data[shard_id_t(0)];

0 commit comments

Comments
 (0)