From: Igor Ryzhov Date: Wed, 15 Sep 2021 19:45:23 +0000 (+0300) Subject: bgpd: fix memory leaks when using route-maps X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=567258511e0070c0b67a539bb17c6452d880a776;p=matthieu%2Ffrr.git bgpd: fix memory leaks when using route-maps 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 (cherry picked from commit ee522f572995074d5b0d840457f40a0eb3f0e40c) --- diff --git a/bgpd/bgp_conditional_adv.c b/bgpd/bgp_conditional_adv.c index 6e80765f86..e8b7f7bc58 100644 --- a/bgpd/bgp_conditional_adv.c +++ b/bgpd/bgp_conditional_adv.c @@ -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 diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 3490a4fa40..f79f16c736 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -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; }