summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas@opensourcerouting.org>2022-09-23 16:54:33 +0200
committerGitHub <noreply@github.com>2022-09-23 16:54:33 +0200
commit344d81ceedd37702503baceece3acb1cde788018 (patch)
tree91ed76a92b502191f4a36e9b490ddb48a5c92727
parentMerge pull request #11997 from sri-mohan1/sri-zebra-dbg1 (diff)
parentbgpd: Cleanup memory leaks associated with t_deferral_timer (diff)
downloadfrr-344d81ceedd37702503baceece3acb1cde788018.tar.xz
frr-344d81ceedd37702503baceece3acb1cde788018.zip
Merge pull request #11982 from samanvithab/bgp_mem_fix
bgpd: multiple memory leak issue fixes
-rw-r--r--bgpd/bgp_ecommunity.c2
-rw-r--r--bgpd/bgp_fsm.c5
-rw-r--r--bgpd/bgp_mplsvpn.c12
-rw-r--r--bgpd/bgp_packet.c5
-rw-r--r--bgpd/bgpd.c16
5 files changed, 36 insertions, 4 deletions
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index f57e9ae88..589d9af1e 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -1383,7 +1383,7 @@ bool ecommunity_del_val(struct ecommunity *ecom, struct ecommunity_val *eval)
XFREE(MTYPE_ECOMMUNITY_VAL, ecom->val);
ecom->val = p;
} else
- ecom->val = NULL;
+ XFREE(MTYPE_ECOMMUNITY_VAL, ecom->val);
return true;
}
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index a8accc25f..ddda10077 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -1464,6 +1464,11 @@ int bgp_stop(struct peer *peer)
/* There is no pending EOR message */
if (gr_info->eor_required == 0) {
+ if (gr_info->t_select_deferral) {
+ void *info = THREAD_ARG(
+ gr_info->t_select_deferral);
+ XFREE(MTYPE_TMP, info);
+ }
THREAD_OFF(gr_info->t_select_deferral);
gr_info->eor_received = 0;
}
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index 5a039b25b..d7fd4bc77 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -1988,9 +1988,15 @@ void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw,
bgp->vpn_policy[afi].tovpn_rd = bgp->vrf_prd_auto;
prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
sizeof(buf));
- bgp->vpn_policy[afi].rtlist[edir] =
- ecommunity_str2com(buf,
- ECOMMUNITY_ROUTE_TARGET, 0);
+
+ /* free up pre-existing memory if any and allocate
+ * the ecommunity attribute with new RD/RT
+ */
+ if (bgp->vpn_policy[afi].rtlist[edir])
+ ecommunity_free(
+ &bgp->vpn_policy[afi].rtlist[edir]);
+ bgp->vpn_policy[afi].rtlist[edir] = ecommunity_str2com(
+ buf, ECOMMUNITY_ROUTE_TARGET, 0);
/* Update import_vrf rt_list */
ecom = bgp->vpn_policy[afi].rtlist[edir];
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index cc1880837..8ae31bf2e 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -2054,6 +2054,11 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
gr_info->eor_required,
"EOR RCV",
gr_info->eor_received);
+ if (gr_info->t_select_deferral) {
+ void *info = THREAD_ARG(
+ gr_info->t_select_deferral);
+ XFREE(MTYPE_TMP, info);
+ }
THREAD_OFF(gr_info->t_select_deferral);
gr_info->eor_required = 0;
gr_info->eor_received = 0;
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 17fde1bb7..b64445f1a 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -3631,7 +3631,12 @@ int bgp_delete(struct bgp *bgp)
gr_info = &bgp->gr_info[afi][safi];
if (!gr_info)
continue;
+ t = gr_info->t_select_deferral;
+ if (t) {
+ void *info = THREAD_ARG(t);
+ XFREE(MTYPE_TMP, info);
+ }
THREAD_OFF(gr_info->t_select_deferral);
t = gr_info->t_route_select;
@@ -3714,6 +3719,17 @@ int bgp_delete(struct bgp *bgp)
bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
}
+ /* Free any memory allocated to holding routemap references */
+ for (afi = 0; afi < AFI_MAX; ++afi) {
+ for (enum vpn_policy_direction dir = 0;
+ dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
+ if (bgp->vpn_policy[afi].rmap_name[dir])
+ XFREE(MTYPE_ROUTE_MAP_NAME,
+ bgp->vpn_policy[afi].rmap_name[dir]);
+ bgp->vpn_policy[afi].rmap[dir] = NULL;
+ }
+ }
+
/* Deregister from Zebra, if needed */
if (IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) {
if (BGP_DEBUG(zebra, ZEBRA))