summaryrefslogtreecommitdiffstats
path: root/src/dhcpcd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-07-23 14:53:01 +0100
committerRoy Marples <roy@marples.name>2019-07-23 14:53:01 +0100
commit05ba1d2542f080f492dcc239bf60ad3c07472245 (patch)
tree4437c6cb0621ceaadcc224e6eda99704185efc7c /src/dhcpcd.c
parent0c97f3e5622409c711c66b737d47fd9274cc4d67 (diff)
downloaddhcpcd-05ba1d2542f080f492dcc239bf60ad3c07472245.tar.xz
dhcpcd: Don't leak memory when routing socket overflows
Diffstat (limited to 'src/dhcpcd.c')
-rw-r--r--src/dhcpcd.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/dhcpcd.c b/src/dhcpcd.c
index a142ef6e..3584d223 100644
--- a/src/dhcpcd.c
+++ b/src/dhcpcd.c
@@ -1135,6 +1135,10 @@ dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx)
/* Work out the current interfaces. */
ifaces = if_discover(ctx, &ifaddrs, ctx->ifc, ctx->ifv);
+ if (ifaces == NULL) {
+ logerr(__func__);
+ return;
+ }
/* Punt departed interfaces */
TAILQ_FOREACH_SAFE(ifp, ctx->ifaces, next, ifn) {
@@ -1144,21 +1148,23 @@ dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx)
}
/* Add new interfaces */
- TAILQ_FOREACH_SAFE(ifp, ifaces, next, ifn) {
+ while ((ifp = TAILQ_FIRST(ifaces)) != NULL ) {
+ TAILQ_REMOVE(ifaces, ifp, next);
ifp1 = if_find(ctx->ifaces, ifp->name);
if (ifp1 != NULL) {
/* If the interface already exists,
* check carrier state. */
eloop_timeout_add_sec(ctx->eloop, 0,
dhcpcd_checkcarrier, ifp1);
+ if_free(ifp);
continue;
}
- TAILQ_REMOVE(ifaces, ifp, next);
TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
if (ifp->active)
eloop_timeout_add_sec(ctx->eloop, 0,
dhcpcd_prestartinterface, ifp);
}
+ free(ifaces);
/* Update address state. */
if_markaddrsstale(ctx->ifaces);