Merge pull request #7556 from donaldsharp/memory_shenanigans

Memory shenanigans
This commit is contained in:
Mark Stapp 2020-11-18 17:31:03 -05:00 committed by GitHub
commit abed797ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 13 deletions

View File

@ -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 */

View File

@ -1703,6 +1703,8 @@ void vrf_import_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
if (!is_inst_match)
listnode_add(to_bgp->vpn_policy[afi].import_vrf,
vname);
else
XFREE(MTYPE_TMP, vname);
/* Check if the source vrf already exports to any vrf,
* first time export requires to setup auto derived RD/RT values.
@ -1725,6 +1727,9 @@ void vrf_import_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
if (!is_inst_match)
listnode_add(from_bgp->vpn_policy[afi].export_vrf,
vname);
else
XFREE(MTYPE_TMP, vname);
/* Update import RT for current VRF using export RT of the VRF we're
* importing from. First though, make sure "import_vrf" has that
* set.
@ -1755,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

View File

@ -1267,8 +1267,6 @@ static uint8_t *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length,
} else {
/* We build a sorted list of interfaces */
ifslist = list_new();
if (!ifslist)
return NULL;
ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
FOR_ALL_INTERFACES (vrf, iif)
listnode_add_sort(ifslist, iif);
@ -1296,6 +1294,7 @@ static uint8_t *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length,
}
list_delete_all_node(ifslist);
list_delete(&ifslist);
}
if (!oi || !on)

View File

@ -6109,6 +6109,7 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty,
json_object_object_add(json_oil, out_ifname,
json_ifp_out);
} else {
proto[0] = '\0';
if (c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_PIM) {
strlcpy(proto, "PIM", sizeof(proto));