Skip to content

Commit

Permalink
Fix memory leak in join handler
Browse files Browse the repository at this point in the history
The timer for deleting a group entry has associated data allocated on the
heap. This data must be freed not only when the timer times out, but also
when receiving a new join for the same group in which case we replace the
currently active timer.

Signed-off-by: Jacques de Laval <[email protected]>
  • Loading branch information
jackuess committed Nov 22, 2022
1 parent 28c8e4f commit c6a1eb1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ static void delete_group_cb(int timeout, void *arg)

ifi = config_find_iface(cbk->ifindex);
if (!ifi)
goto done;
return;

logit(LOG_DEBUG, 0, "Group membership timeout for %s on %s",
inet_fmt(cbk->g->al_addr, s1, sizeof(s1)), ifi->ifi_name);
Expand All @@ -969,8 +969,6 @@ static void delete_group_cb(int timeout, void *arg)

TAILQ_REMOVE(&ifi->ifi_groups, g, al_link);
free(g);
done:
free(cbk);
}

/*
Expand All @@ -979,7 +977,9 @@ static void delete_group_cb(int timeout, void *arg)
static int delete_group_timer(int ifindex, struct listaddr *g, int tmo)
{
cbk_t *cbk;
int tid;

/* cbk is freed as a side effect of pev_timer_del (via the deletion cb) */
cbk = calloc(1, sizeof(cbk_t));
if (!cbk) {
logit(LOG_ERR, errno, "%s(): Failed allocating memory", __func__);
Expand All @@ -992,7 +992,10 @@ static int delete_group_timer(int ifindex, struct listaddr *g, int tmo)
/* Record mtime for IPC "show igmp" */
// g->al_mtime = virtual_time;

return pev_timer_add(tmo * 1000000, 0, delete_group_cb, cbk);
tid = pev_timer_add(tmo * 1000000, 0, delete_group_cb, cbk);
pev_timer_set_cb_del(tid, free);

return tid;
}

/*
Expand Down

0 comments on commit c6a1eb1

Please sign in to comment.