aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-12-13 12:23:14 +0000
committersaturneric <[email protected]>2023-12-13 12:23:14 +0000
commit6a9ca113beb78f5d7315e2a40025ea5bdcdb8d17 (patch)
tree0825689bb9e8bd01c7f046dd343b09807f8a76d2 /src
parentfeat: mimalloc support valgrind (diff)
downloadGpgFrontend-6a9ca113beb78f5d7315e2a40025ea5bdcdb8d17.tar.gz
GpgFrontend-6a9ca113beb78f5d7315e2a40025ea5bdcdb8d17.zip
fix: slove a memory issue found by valgrind
Diffstat (limited to 'src')
-rw-r--r--src/core/module/GlobalModuleContext.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp
index 9eddb57a..e900535c 100644
--- a/src/core/module/GlobalModuleContext.cpp
+++ b/src/core/module/GlobalModuleContext.cpp
@@ -116,21 +116,21 @@ class GlobalModuleContext::Impl {
return false;
}
- ModuleRegisterInfo register_info;
- register_info.module = module;
- register_info.channel = acquire_new_unique_channel();
- register_info.task_runner =
+ auto register_info =
+ GpgFrontend::SecureCreateSharedObject<ModuleRegisterInfo>();
+ register_info->module = module;
+ register_info->channel = acquire_new_unique_channel();
+ register_info->task_runner =
GpgFrontend::SecureCreateSharedObject<Thread::TaskRunner>();
- register_info.task_runner->Start();
+ register_info->task_runner->Start();
// move module to its task runner' thread
- register_info.module->setParent(nullptr);
- register_info.module->moveToThread(register_info.task_runner->GetThread());
+ register_info->module->setParent(nullptr);
+ register_info->module->moveToThread(
+ register_info->task_runner->GetThread());
// Register the module with its identifier.
- module_register_table_[module->GetModuleIdentifier()] =
- GpgFrontend::SecureCreateSharedObject<ModuleRegisterInfo>(
- std::move(register_info));
+ module_register_table_[module->GetModuleIdentifier()] = register_info;
SPDLOG_DEBUG("successfully registered module: {}",
module->GetModuleIdentifier());
@@ -148,8 +148,19 @@ class GlobalModuleContext::Impl {
}
auto module_info = module_info_opt.value();
+
+ // try to get module from module info
+ auto module = module_info->module;
+ if (module == nullptr) {
+ SPDLOG_ERROR(
+ "module id {} at register table is releated to a null module",
+ module_id);
+ return false;
+ }
+
// Activate the module if it is not already active.
- if (!module_info->activate && module_info->module->Active()) {
+ if (!module_info->activate) {
+ module->Active();
module_info->activate = true;
}