Skip to content

Commit

Permalink
Fixed issue with elements not being removed correctly with TAILQ
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Skarhed committed Nov 23, 2022
1 parent e0bd167 commit 5e0be19
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
20 changes: 14 additions & 6 deletions src/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ typedef struct {
int num;
} cbk_t;

extern struct ifaces ifaces;

/*
* Forward declarations.
*/
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 5e0be19

Please sign in to comment.