]> 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)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 15 Sep 2021 19:45:23 +0000 (22:45 +0300)
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>
bgpd/bgp_conditional_adv.c
bgpd/bgp_route.c

index 329bd3d696cadd11c172a609d95fe1b936c79284..82eb8a815e2ad20761aa96e010d281b460e62a44 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 bc8ce6b4f4ab8eb2efa96b4553050eaaaed7270c..5a16fecc2674f557c15276e2a23e1093eda551b4 100644 (file)
@@ -10806,6 +10806,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;
                        }