]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
route: Fix memory leak on option or freed route
authorRoy Marples <roy@marples.name>
Sun, 3 Mar 2019 23:21:33 +0000 (23:21 +0000)
committerRoy Marples <roy@marples.name>
Sun, 3 Mar 2019 23:21:33 +0000 (23:21 +0000)
In this case there is no interface to compare the metric for.
As such, compare on pointer so we can maintain a free list.

src/route.c

index 666a60972e8a4a7a2a960000462a88b8b3e3074a..b570168de8cf415e467b0bdd7defc5906db97e89 100644 (file)
@@ -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;