diff options
| author | yangwei <[email protected]> | 2024-11-25 19:23:01 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-11-25 19:23:01 +0800 |
| commit | ca52d2fbc27e8b45ed44055bfd57f3110fb3f421 (patch) | |
| tree | 5d9af72af106dd7cfbc51c8487ea2dfcb26382c7 /infra/module_manager | |
| parent | efefab960010412c3bbb769cba05325c6b4ca65e (diff) | |
🐞 fix(utable): fix memleak in test case
Diffstat (limited to 'infra/module_manager')
| -rw-r--r-- | infra/module_manager/module_manager.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/infra/module_manager/module_manager.c b/infra/module_manager/module_manager.c index 1f8b7be..600327d 100644 --- a/infra/module_manager/module_manager.c +++ b/infra/module_manager/module_manager.c @@ -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; } |
