# HG changeset patch # User Roy Marples # Date 1564481064 -3600 # Node ID 8e54887526a69aeb382e8501d87d4dd82e09711b # Parent 88476f3f04d07da632515f1d9f29ad50a55bb385 routes: Fix a NULL dereference error for global static routes No idea why you would want them, but just in case ..... diff -r 88476f3f04d0 -r 8e54887526a6 src/dhcpcd.c --- a/src/dhcpcd.c Tue Jul 30 10:29:51 2019 +0100 +++ b/src/dhcpcd.c Tue Jul 30 11:04:24 2019 +0100 @@ -2125,13 +2125,13 @@ } free(ctx.ifaces); } + free_options(&ctx, ifo); #ifdef HAVE_OPEN_MEMSTREAM if (ctx.script_fp) fclose(ctx.script_fp); #endif free(ctx.script_buf); free(ctx.script_env); - free_options(&ctx, ifo); rt_dispose(&ctx); free(ctx.duid); if (ctx.link_fd != -1) { diff -r 88476f3f04d0 -r 8e54887526a6 src/if-options.c --- a/src/if-options.c Tue Jul 30 10:29:51 2019 +0100 +++ b/src/if-options.c Tue Jul 30 11:04:24 2019 +0100 @@ -2612,6 +2612,7 @@ { size_t i; #ifdef RT_FREE_ROUTE_TABLE + struct interface *ifp; struct rt *rt; #endif struct dhcp_opt *opt; @@ -2640,9 +2641,12 @@ /* Stupidly, we don't know the interface when creating the options. * As such, make sure each route has one so they can goto the * free list. */ - RB_TREE_FOREACH(rt, &ifo->routes) { - if (rt->rt_ifp == NULL) - rt->rt_ifp = TAILQ_FIRST(ctx->ifaces); + ifp = ctx->ifaces != NULL ? TAILQ_FIRST(ctx->ifaces) : NULL; + if (ifp != NULL) { + RB_TREE_FOREACH(rt, &ifo->routes) { + if (rt->rt_ifp == NULL) + rt->rt_ifp = ifp; + } } #endif rt_headclear0(ctx, &ifo->routes, AF_UNSPEC);