diff options
| author | Donald Sharp <sharpd@nvidia.com> | 2020-11-18 12:50:48 -0500 |
|---|---|---|
| committer | Donald Sharp <sharpd@nvidia.com> | 2020-11-18 12:50:48 -0500 |
| commit | 6a37bfb7e50b86df9b5c6cce38c6a86fffb90ed9 (patch) | |
| tree | 526973b815cf966b6bc567708c246fb2dcdfa014 | |
| parent | b9d4546253d3d5c55fa45ac07943faaed3ceb253 (diff) | |
bgpd: Prevent ecommunity_ecom2str memory leak
We were allocating but never freeing memory associated with the
ecommunity_ecom2str allocation.
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
| -rw-r--r-- | bgpd/bgp_ecommunity.c | 2 | ||||
| -rw-r--r-- | bgpd/bgp_mplsvpn.c | 27 |
2 files changed, 18 insertions, 11 deletions
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index 74cbf3a80a..43bfb3e2bc 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -903,7 +903,7 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) int str_size; char *str_buf; - if (ecom->size == 0) + if (!ecom || ecom->size == 0) return XCALLOC(MTYPE_ECOMMUNITY_STR, 1); /* ecom strlen + space + null term */ diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 612c8ceee7..3bc4c03233 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -1760,19 +1760,26 @@ void vrf_import_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp, if (debug) { const char *from_name; + char *ecom1, *ecom2; from_name = from_bgp->name ? from_bgp->name : VRF_DEFAULT_NAME; - zlog_debug("%s from %s to %s first_export %u import-rt %s export-rt %s", - __func__, from_name, export_name, first_export, - to_bgp->vpn_policy[afi].rtlist[idir] ? - (ecommunity_ecom2str(to_bgp->vpn_policy[afi]. - rtlist[idir], - ECOMMUNITY_FORMAT_ROUTE_MAP, 0)) : " ", - to_bgp->vpn_policy[afi].rtlist[edir] ? - (ecommunity_ecom2str(to_bgp->vpn_policy[afi]. - rtlist[edir], - ECOMMUNITY_FORMAT_ROUTE_MAP, 0)) : " "); + + ecom1 = ecommunity_ecom2str( + to_bgp->vpn_policy[afi].rtlist[idir], + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + + ecom2 = ecommunity_ecom2str( + to_bgp->vpn_policy[afi].rtlist[edir], + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + + zlog_debug( + "%s from %s to %s first_export %u import-rt %s export-rt %s", + __func__, from_name, export_name, first_export, ecom1, + ecom2); + + ecommunity_strfree(&ecom1); + ecommunity_strfree(&ecom2); } /* Does "import_vrf" first need to export its routes or that |
