Skip to content

Commit

Permalink
Merge pull request #16649 from opensourcerouting/fix/free_memory_on_r…
Browse files Browse the repository at this point in the history
…eturn

bgpd: Free epvn_overlay memory on error
  • Loading branch information
donaldsharp authored Aug 24, 2024
2 parents ab2fd98 + 5eb80ed commit f85dfb3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static void *evpn_overlay_hash_alloc(void *p)
return p;
}

static void evpn_overlay_free(struct bgp_route_evpn *bre)
void evpn_overlay_free(struct bgp_route_evpn *bre)
{
XFREE(MTYPE_BGP_EVPN_OVERLAY, bre);
}
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,5 +646,6 @@ bgp_attr_set_vnc_subtlvs(struct attr *attr,
}

extern bool route_matches_soo(struct bgp_path_info *pi, struct ecommunity *soo);
extern void evpn_overlay_free(struct bgp_route_evpn *bre);

#endif /* _QUAGGA_BGP_ATTR_H */
3 changes: 3 additions & 0 deletions bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -4921,6 +4921,7 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
flog_err(EC_BGP_EVPN_ROUTE_INVALID,
"%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
peer->bgp->vrf_id, peer->host, psize);
evpn_overlay_free(evpn);
return -1;
}

Expand Down Expand Up @@ -4953,6 +4954,7 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
EC_BGP_EVPN_ROUTE_INVALID,
"%u:%s - Rx EVPN Type-5 NLRI with invalid IP Prefix length %d",
peer->bgp->vrf_id, peer->host, ippfx_len);
evpn_overlay_free(evpn);
return -1;
}
p.prefix.prefix_addr.ip_prefix_length = ippfx_len;
Expand Down Expand Up @@ -5033,6 +5035,7 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
}
bgp_withdraw(peer, (struct prefix *)&p, addpath_id, afi, safi,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, &label, 1);
evpn_overlay_free(evpn);
}

return 0;
Expand Down
4 changes: 4 additions & 0 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -4608,6 +4608,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
*/
if ((afi == AFI_L2VPN) && evpn)
bgp_attr_set_evpn_overlay(attr, evpn);
else
evpn_overlay_free(evpn);
bgp_adj_in_set(dest, peer, attr, addpath_id, &bgp_labels);
}

Expand Down Expand Up @@ -4770,6 +4772,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
*/
if (soft_reconfig && (afi == AFI_L2VPN) && evpn)
bgp_attr_set_evpn_overlay(&new_attr, evpn);
else
evpn_overlay_free(evpn);

/* Apply incoming route-map.
* NB: new_attr may now contain newly allocated values from route-map
Expand Down

0 comments on commit f85dfb3

Please sign in to comment.