From: Roy Marples Date: Sun, 3 Mar 2019 23:21:33 +0000 (+0000) Subject: route: Fix memory leak on option or freed route X-Git-Tag: v8.0.0~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46495be94d035fe80163c5c0bcbca15c36a3aea0;p=thirdparty%2Fdhcpcd.git route: Fix memory leak on option or freed route In this case there is no interface to compare the metric for. As such, compare on pointer so we can maintain a free list. --- diff --git a/src/route.c b/src/route.c index 666a6097..b570168d 100644 --- a/src/route.c +++ b/src/route.c @@ -71,7 +71,10 @@ rt_compare(__unused void *context, const void *node1, const void *node2) return c; /* Finally by interface metric. */ - if (rt1->rt_ifp != NULL && rt2->rt_ifp != NULL) + if (rt1->rt_ifp == NULL || rt2->rt_ifp == NULL) + /* option or freed route */ + c = rt1 == rt2 ? 0 : rt1 < rt2 ? -1 : 1; + else c = (int)(rt1->rt_ifp->metric - rt2->rt_ifp->metric); return c;