From aa4fede3066beedfcef089893bae35e376d0e199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 21:16:13 +0100 Subject: [PATCH] plugin: use tll_free_and_free() to free the global plugin list --- plugin.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/plugin.c b/plugin.c index 3cc20db..5291250 100644 --- a/plugin.c +++ b/plugin.c @@ -17,20 +17,23 @@ struct plugin { static tll(struct plugin) libs = tll_init(); +static void +free_lib(struct plugin plug) +{ + dlerror(); + dlclose(plug.lib); + + const char *dl_error = dlerror(); + if (dl_error != NULL) + LOG_ERR("%s: dlclose(): %s", plug.name, dl_error); + + free(plug.name); +} + static void __attribute__((destructor)) fini(void) { - tll_foreach(libs, plug) { - dlerror(); - dlclose(plug->item.lib); - - const char *dl_error = dlerror(); - if (dl_error != NULL) - LOG_ERR("%s: dlclose(): %s", plug->item.name, dl_error); - - free(plug->item.name); - tll_remove(libs, plug); - } + tll_free_and_free(libs, free_lib); } const struct module_info *