summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-09-25 17:44:27 +0800
committeryangwei <[email protected]>2024-09-25 17:44:27 +0800
commitc550acef84ee54915518f776a179901d94d481f4 (patch)
treefd16e33e504b2055728702ecd0f8216aaf20ec29
parent154e727f07fd2e1a9544e1a3941865fe247bd011 (diff)
✨ feat(module manager): store spec path and cb name
-rw-r--r--infra/module_manager/module_manager.c9
-rw-r--r--infra/module_manager/module_manager_interna.h3
-rw-r--r--infra/module_manager/test/gtest_module_manager_main.cpp4
3 files changed, 13 insertions, 3 deletions
diff --git a/infra/module_manager/module_manager.c b/infra/module_manager/module_manager.c
index 22491d3..3006bee 100644
--- a/infra/module_manager/module_manager.c
+++ b/infra/module_manager/module_manager.c
@@ -62,9 +62,9 @@ int module_specs_load(toml_table_t* conf, struct module_spec_load **mod_spec)
if (!mod_spec[i]->on_exit_cb) {
fprintf(stderr, "Could not load exit function %s: %s\n", exit_func_name, dlerror());
}
- FREE(path);
- FREE(init_func_name);
- FREE(exit_func_name);
+ mod_spec[i]->path=path;
+ mod_spec[i]->init_cb_name=init_func_name;
+ mod_spec[i]->exit_cb_name=exit_func_name;
}
return mod_num;
MODULE_SPEC_LOAD_ERROR:
@@ -127,6 +127,9 @@ void stellar_module_manager_free(struct stellar_module_manager *mod_mgr)
{
mod_mgr->schema.module_specs[i].on_exit_cb(mod_mgr, mod_mgr->schema.module_specs[i].mod);
}
+ if(mod_mgr->schema.module_specs[i].path)FREE(mod_mgr->schema.module_specs[i].path);
+ if(mod_mgr->schema.module_specs[i].init_cb_name)FREE(mod_mgr->schema.module_specs[i].init_cb_name);
+ if(mod_mgr->schema.module_specs[i].exit_cb_name)FREE(mod_mgr->schema.module_specs[i].exit_cb_name);
}
FREE(mod_mgr->schema.module_specs);
}
diff --git a/infra/module_manager/module_manager_interna.h b/infra/module_manager/module_manager_interna.h
index e6b1e81..7d28b50 100644
--- a/infra/module_manager/module_manager_interna.h
+++ b/infra/module_manager/module_manager_interna.h
@@ -24,6 +24,9 @@ struct module_spec_load
struct stellar_module *mod;
module_on_init_func *on_init_cb;
module_on_exit_func *on_exit_cb;
+ char *path;
+ char *init_cb_name;
+ char *exit_cb_name;
bool is_init_succ;
}__attribute__((aligned(sizeof(void*))));
diff --git a/infra/module_manager/test/gtest_module_manager_main.cpp b/infra/module_manager/test/gtest_module_manager_main.cpp
index 7f0dc9a..74aa611 100644
--- a/infra/module_manager/test/gtest_module_manager_main.cpp
+++ b/infra/module_manager/test/gtest_module_manager_main.cpp
@@ -39,6 +39,10 @@ TEST(module_manager_internal, module_specs_load) {
EXPECT_EQ(specs[0].on_init_cb, gtest_mock_init);
EXPECT_EQ(specs[0].on_exit_cb, gtest_mock_exit);
+
+ if(specs->path)free(specs->path);
+ if(specs->init_cb_name)free(specs->init_cb_name);
+ if(specs->exit_cb_name)free(specs->exit_cb_name);
free(specs);
toml_free(conf);