From 0e92a10b816a0ce2c2cd7581dc4e09faa4a0adda Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 28 Apr 2024 08:51:03 +0800 Subject: [PATCH] erasure-code/shec: use free() to release alloc()'ed memory chunk ASan warns ``` ==445793==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x602000039b10 #0 0x5604a544112d in operator delete(void*) (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/unittest_erasure_code_shec_all+0x1e012d) (BuildId: 8cfc74d22471b6905f9b23304aed2af945265a13) #1 0x7fc14752f588 in ErasureCodeShecTableCache::~ErasureCodeShecTableCache() /home/jenkins-build/build/workspace/ceph-pull-requests/src/erasure-code/shec/ErasureCodeShecTableCache.cc:61:19 #2 0x5604a544ccbe in ParameterTest_parameter_all_Test::TestBody() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/erasure-code/TestErasureCodeShec_all.cc:263:1 ... 0x602000039b10 is located 0 bytes inside of 4-byte region [0x602000039b10,0x602000039b14) allocated by thread T0 here: #0 0x5604a5405afe in malloc (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/unittest_erasure_code_shec_all+0x1a4afe) (BuildId: 8cfc74d22471b6905f9b23304aed2af945265a13) #1 0x7fc1474c9617 in reed_sol_vandermonde_coding_matrix /home/jenkins-build/build/workspace/ceph-pull-requests/src/erasure-code/jerasure/jerasure/src/reed_sol.c:86:10 #2 0x7fc147528634 in ErasureCodeShec::shec_reedsolomon_coding_matrix(int) /home/jenkins-build/build/workspace/ceph-pull-requests/src/erasure-code/shec/ErasureCodeShec.cc:514:12 #3 0x7fc147526cd8 in ErasureCodeShecReedSolomonVandermonde::prepare() /home/jenkins-build/build/workspace/ceph-pull-requests/src/erasure-code/shec/ErasureCodeShec.cc:390:14 #4 0x7fc1475187aa in ErasureCodeShec::init(std::map, std::allocator >, std::__cxx11::basic_string, std::allocator >, std::less, std::allocator > >, std::allocator, std::allocator > const, std::__cxx11::basic_string, std::allocator > > > >&, std::ostream*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/erasure-code/shec/ErasureCodeShec.cc:57:3 ``` where we use `delete` to free the encoder matrix allocated using `malloc()`. as jerasure is a library implemented in C language, unless we want to reimplment it in C++, we should use `free()` to free the memory chunk allocated by `reed_sol_vandermonde_coding_matrix()`. also, please note, jerasure does not provide a function to free the memory allocated by this function, we have to explore its implementation, and use `malloc()` directly. this should silence the ASan warning. Signed-off-by: Kefu Chai --- src/erasure-code/shec/ErasureCodeShecTableCache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/erasure-code/shec/ErasureCodeShecTableCache.cc b/src/erasure-code/shec/ErasureCodeShecTableCache.cc index 2f9a60b62bc64..202b01a66409a 100644 --- a/src/erasure-code/shec/ErasureCodeShecTableCache.cc +++ b/src/erasure-code/shec/ErasureCodeShecTableCache.cc @@ -58,7 +58,7 @@ ErasureCodeShecTableCache::~ErasureCodeShecTableCache() for (table_it = tables_it__->second.begin(); table_it != tables_it__->second.end(); ++table_it) { if (table_it->second) { if (*(table_it->second)) { - delete *(table_it->second); + free(*(table_it->second)); } delete table_it->second; }