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>
This commit is contained in:
Donald Sharp 2020-11-18 12:50:48 -05:00
parent b9d4546253
commit 6a37bfb7e5
2 changed files with 18 additions and 11 deletions

View File

@ -903,7 +903,7 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
int str_size; int str_size;
char *str_buf; char *str_buf;
if (ecom->size == 0) if (!ecom || ecom->size == 0)
return XCALLOC(MTYPE_ECOMMUNITY_STR, 1); return XCALLOC(MTYPE_ECOMMUNITY_STR, 1);
/* ecom strlen + space + null term */ /* ecom strlen + space + null term */

View File

@ -1760,19 +1760,26 @@ void vrf_import_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
if (debug) { if (debug) {
const char *from_name; const char *from_name;
char *ecom1, *ecom2;
from_name = from_bgp->name ? from_bgp->name : from_name = from_bgp->name ? from_bgp->name :
VRF_DEFAULT_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, ecom1 = ecommunity_ecom2str(
to_bgp->vpn_policy[afi].rtlist[idir] ? to_bgp->vpn_policy[afi].rtlist[idir],
(ecommunity_ecom2str(to_bgp->vpn_policy[afi]. ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
rtlist[idir],
ECOMMUNITY_FORMAT_ROUTE_MAP, 0)) : " ", ecom2 = ecommunity_ecom2str(
to_bgp->vpn_policy[afi].rtlist[edir] ? to_bgp->vpn_policy[afi].rtlist[edir],
(ecommunity_ecom2str(to_bgp->vpn_policy[afi]. ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
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 /* Does "import_vrf" first need to export its routes or that