From 5e0be19f0ed6237aa72e69698a613cff0c08e14e Mon Sep 17 00:00:00 2001 From: Fredrik Skarhed Date: Wed, 23 Nov 2022 15:17:48 +0100 Subject: [PATCH] Fixed issue with elements not being removed correctly with TAILQ --- src/config.c | 2 +- src/defs.h | 2 ++ src/iface.c | 20 ++++++++++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/config.c b/src/config.c index 0e15ec1..b50855d 100644 --- a/src/config.c +++ b/src/config.c @@ -9,7 +9,7 @@ /* * Exported variables. */ -TAILQ_HEAD(ifaces, ifi) ifaces = TAILQ_HEAD_INITIALIZER(ifaces); +struct ifaces ifaces = TAILQ_HEAD_INITIALIZER(ifaces); void config_set_ifflag(uint32_t flag) { diff --git a/src/defs.h b/src/defs.h index 27ce547..01901d0 100644 --- a/src/defs.h +++ b/src/defs.h @@ -53,6 +53,8 @@ typedef void (*ihfunc_t) (int); #define NELEMS(a) (sizeof((a)) / sizeof((a)[0])) +TAILQ_HEAD(ifaces, ifi); + /* * External declarations for global variables and functions. */ diff --git a/src/iface.c b/src/iface.c index 8f21802..3ebebee 100644 --- a/src/iface.c +++ b/src/iface.c @@ -15,6 +15,8 @@ typedef struct { int num; } cbk_t; +extern struct ifaces ifaces; + /* * Forward declarations. */ @@ -35,7 +37,6 @@ static int send_query_timer (int ifindex, struct listaddr *g, int delay, int static void group_version_cb (int timeout, void *arg); static int group_version_timer(int ifindex, struct listaddr *g); - void iface_init(void) { struct ifi *ifi; @@ -57,12 +58,19 @@ void iface_init(void) void iface_exit(void) { struct listaddr *a, *tmp; - struct phaddr *pa, *pat; - struct ifi *ifi; + struct ifi *ifi, *ifi_tmp; - for (ifi = config_iface_iter(1); ifi; ifi = config_iface_iter(0)) { - iface_del(ifi->ifi_ifindex, 0); - free(ifi); + /* Deletes the entire list and all sub-lists. */ + TAILQ_FOREACH_SAFE(ifi, &ifaces, ifi_link, ifi_tmp) { + + iface_del(ifi->ifi_ifindex, 0); + + TAILQ_FOREACH_SAFE(a, &ifi->ifi_static, al_link, tmp) { + TAILQ_REMOVE(&ifi->ifi_static, a, al_link); + free(a); + } + TAILQ_REMOVE(&ifaces, ifi, ifi_link); + free(ifi); } }