🐞 fix(utable): fix memleak in test case

This commit is contained in:
yangwei
2024-11-25 19:23:01 +08:00
parent efefab9600
commit ca52d2fbc2
4 changed files with 31 additions and 22 deletions

View File

@@ -70,6 +70,10 @@ struct module_manager *module_manager_new_with_toml(const char *toml_path, int m
struct module_hooks mod_hooks[mod_num];
memset(mod_hooks, 0, sizeof(mod_hooks));
char *path = NULL;
char *instance_init_cb_name = NULL, *instance_exit_cb_name = NULL, *thread_init_cb_name = NULL,
*thread_exit_cb_name = NULL;
for (int i = 0; i < mod_num; i++)
{
toml_table_t* toml_mod = toml_table_at(mod_array, i);
@@ -80,21 +84,15 @@ struct module_manager *module_manager_new_with_toml(const char *toml_path, int m
const char *thread_init_func_name_raw = toml_raw_in(toml_mod, "thread_init");
const char *thread_exit_func_name_raw = toml_raw_in(toml_mod, "thread_exit");
char *path = NULL;
char *instance_init_cb_name = NULL, *instance_exit_cb_name = NULL, *thread_init_cb_name = NULL,
*thread_exit_cb_name = NULL;
toml_rtos(path_raw, &path);
toml_rtos(init_func_name_raw, &instance_init_cb_name);
toml_rtos(exit_func_name_raw, &instance_exit_cb_name);
toml_rtos(thread_init_func_name_raw, &thread_init_cb_name);
toml_rtos(thread_exit_func_name_raw, &thread_exit_cb_name);
void* handle = dlopen(path, RTLD_NOW|RTLD_LAZY|RTLD_GLOBAL);
if (!handle) {
fprintf(stderr, "Error loading module %s: %s\n", path, dlerror());
if(path)FREE(path);
if (!handle)
{
break;
}
toml_rtos(init_func_name_raw, &instance_init_cb_name);
if (instance_init_cb_name)
{
mod_hooks[i].on_instance_init_cb =
@@ -103,6 +101,8 @@ struct module_manager *module_manager_new_with_toml(const char *toml_path, int m
FREE(instance_init_cb_name);
}
toml_rtos(exit_func_name_raw, &instance_exit_cb_name);
if (instance_exit_cb_name)
{
mod_hooks[i].on_instance_exit_cb =
@@ -110,6 +110,7 @@ struct module_manager *module_manager_new_with_toml(const char *toml_path, int m
FREE(instance_exit_cb_name);
}
toml_rtos(thread_init_func_name_raw, &thread_init_cb_name);
if (thread_init_cb_name)
{
mod_hooks[i].on_thread_init_cb =
@@ -117,6 +118,7 @@ struct module_manager *module_manager_new_with_toml(const char *toml_path, int m
FREE(thread_init_cb_name);
}
toml_rtos(thread_exit_func_name_raw, &thread_exit_cb_name);
if (thread_exit_cb_name)
{
mod_hooks[i].on_thread_exit_cb =
@@ -146,6 +148,12 @@ void module_manager_free(struct module_manager *mod_mgr)
}
FREE(mod_mgr->descriptors);
}
struct polling_node *node, *tmp;
LL_FOREACH_SAFE(mod_mgr->node_list, node, tmp)
{
LL_DELETE(mod_mgr->node_list, node);
FREE(node);
}
FREE(mod_mgr);
return;
}