diff options
| author | Igor Ryzhov <iryzhov@nfware.com> | 2021-09-15 22:45:23 +0300 | 
|---|---|---|
| committer | Igor Ryzhov <iryzhov@nfware.com> | 2021-09-15 22:45:23 +0300 | 
| commit | ee522f572995074d5b0d840457f40a0eb3f0e40c (patch) | |
| tree | ec5508957ab808bca33d710092a256b689b2a315 /bgpd/bgp_conditional_adv.c | |
| parent | bc4477ecbdca408c8a3757f687fd18564af754ec (diff) | |
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 <iryzhov@nfware.com>
Diffstat (limited to 'bgpd/bgp_conditional_adv.c')
| -rw-r--r-- | bgpd/bgp_conditional_adv.c | 15 | 
1 files changed, 8 insertions, 7 deletions
diff --git a/bgpd/bgp_conditional_adv.c b/bgpd/bgp_conditional_adv.c index 329bd3d696..82eb8a815e 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  | 
