]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: fix memory leaks when using route-maps
authorIgor Ryzhov <iryzhov@nfware.com>
Wed, 15 Sep 2021 19:45:23 +0000 (22:45 +0300)
committermergify-bot <noreply@mergify.io>
Fri, 17 Sep 2021 12:48:38 +0000 (12:48 +0000)
There are places where we use route-maps using duplicated attributes and
neither intern nor flush them after the usage. If a route-map has set
rules for aspath/communities, they will be allocated and never freed.
We should always flush unneeded duplicated attributes.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
(cherry picked from commit ee522f572995074d5b0d840457f40a0eb3f0e40c)

bgpd/bgp_conditional_adv.c
bgpd/bgp_route.c

index 6e80765f8671ce734bd53e1f6c9a1e82978e3b0a..e8b7f7bc58426e008e8368b8b124cb210cf69424 100644 (file)
@@ -49,9 +49,9 @@ bgp_check_rmap_prefixes_in_bgp_table(struct bgp_table *table,
                        RESET_FLAG(dummy_attr.rmap_change_flags);
 
                        ret = route_map_apply(rmap, dest_p, &path);
-                       if (ret != RMAP_PERMITMATCH)
-                               bgp_attr_flush(&dummy_attr);
-                       else {
+                       bgp_attr_flush(&dummy_attr);
+
+                       if (ret == RMAP_PERMITMATCH) {
                                bgp_dest_unlock_node(dest);
                                if (BGP_DEBUG(update, UPDATE_OUT))
                                        zlog_debug(
@@ -84,6 +84,7 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi,
        struct update_subgroup *subgrp;
        struct attr dummy_attr = {0}, attr = {0};
        struct bgp_path_info_extra path_extra = {0};
+       route_map_result_t ret;
 
        paf = peer_af_find(peer, afi, safi);
        if (!paf)
@@ -114,11 +115,11 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi,
 
                        RESET_FLAG(dummy_attr.rmap_change_flags);
 
-                       if (route_map_apply(rmap, dest_p, &path)
-                           != RMAP_PERMITMATCH) {
-                               bgp_attr_flush(&dummy_attr);
+                       ret = route_map_apply(rmap, dest_p, &path);
+                       bgp_attr_flush(&dummy_attr);
+
+                       if (ret != RMAP_PERMITMATCH)
                                continue;
-                       }
 
                        if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)
                            || (addpath_capable
index 3490a4fa401e1ff10a1f1546df52859a293c2d2a..f79f16c7367139a9313b41b58a8c53616ba093be 100644 (file)
@@ -10537,6 +10537,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
                                path.attr = &dummy_attr;
 
                                ret = route_map_apply(rmap, dest_p, &path);
+                               bgp_attr_flush(&dummy_attr);
                                if (ret == RMAP_DENYMATCH)
                                        continue;
                        }