summaryrefslogtreecommitdiffstats
path: root/src/erasure-code
diff options
context:
space:
mode:
authorRongqi Sun <sunrongqi@huawei.com>2024-05-21 11:16:14 +0200
committerRongqi Sun <sunrongqi@huawei.com>2024-05-28 05:01:57 +0200
commitc351eb24f1c110807baa14a77d521eea1198f2bc (patch)
tree7cd5ce6fdb9f1f03a023aec7d10410d3724071b6 /src/erasure-code
parentMerge PR #56642 into main (diff)
downloadceph-c351eb24f1c110807baa14a77d521eea1198f2bc.tar.xz
ceph-c351eb24f1c110807baa14a77d521eea1198f2bc.zip
ec: free plugin memory when it destructs
When sanitizer is enabled, unittest_erasure_code_shec_thread shows, ``` ================================================================= ==737674==ERROR: LeakSanitizer: detected memory leaks Direct leak of 1360 byte(s) in 5 object(s) allocated from: #0 0xaaaadddffb08 in operator new(unsigned long) (/root/ceph/build/bin/unittest_erasure_code_shec_thread+0x1bfb08) (BuildId: 187a0067c45bf30f4d0bd2df83a32e0127ef03a1) #1 0xffff800bb004 in __erasure_code_init /root/ceph/src/erasure-code/shec/ErasureCodePluginShec.cc:81:36 #2 0xaaaadde08de0 in thread1(void*) /root/ceph/src/test/erasure-code/TestErasureCodeShec_thread.cc:100:5 #3 0xffff7f45d5c4 in start_thread nptl/./nptl/pthread_create.c:442:8 #4 0xffff7f4c5ed8 misc/../sysdeps/unix/sysv/linux/aarch64/clone.S:79 SUMMARY: AddressSanitizer: 1360 byte(s) leaked in 5 allocation(s). ``` When the plugin destructed, memory should be freed without unloading the dynamic library. Signed-off-by: Rongqi Sun <sunrongqi@huawei.com>
Diffstat (limited to 'src/erasure-code')
-rw-r--r--src/erasure-code/ErasureCodePlugin.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/erasure-code/ErasureCodePlugin.cc b/src/erasure-code/ErasureCodePlugin.cc
index f189b91fdfe..82e4f1b198b 100644
--- a/src/erasure-code/ErasureCodePlugin.cc
+++ b/src/erasure-code/ErasureCodePlugin.cc
@@ -15,6 +15,7 @@
*
*/
+#include <cassert>
#include <errno.h>
#include "ceph_ver.h"
@@ -39,15 +40,14 @@ ErasureCodePluginRegistry::ErasureCodePluginRegistry() = default;
ErasureCodePluginRegistry::~ErasureCodePluginRegistry()
{
- if (disable_dlclose)
- return;
-
- for (std::map<std::string,ErasureCodePlugin*>::iterator i = plugins.begin();
- i != plugins.end();
- ++i) {
- void *library = i->second->library;
- delete i->second;
- dlclose(library);
+ for (auto& name_plugin : plugins) {
+ auto *plugin = name_plugin.second;
+ assert(plugin);
+ void *library = plugin->library;
+ delete plugin;
+ if (!disable_dlclose) {
+ dlclose(library);
+ }
}
}