]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Prevent memory leak if route is rejected early
authorDonald Sharp <sharpd@nvidia.com>
Fri, 6 Aug 2021 20:00:32 +0000 (16:00 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Mon, 9 Aug 2021 11:55:07 +0000 (07:55 -0400)
When receiving a route via zapi, if the route is rejected
there exists a code path where we would not free the corresponding
re created.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
zebra/zapi_msg.c

index 27fb5d7c228f27292c34fc39b4d4b6149d47558e..08ad390d322d79952b558888de57005bc4673b50 100644 (file)
@@ -2110,6 +2110,13 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
        ret = rib_add_multipath_nhe(afi, api.safi, &api.prefix, src_p,
                                    re, &nhe);
 
+       /*
+        * rib_add_multipath_nhe only fails in a couple spots
+        * and in those spots we have not freed memory
+        */
+       if (ret == -1)
+               XFREE(MTYPE_RE, re);
+
        /* At this point, these allocations are not needed: 're' has been
         * retained or freed, and if 're' still exists, it is using
         * a reference to a shared group object.