Skip to content

Commit 6855bf2

Browse files
committed
bgpd: fix bgp evpn memory leaks when adj-rib-in is disabled
Some bgp evpn memory contexts are not freed at the end of the bgp process. > ================================================================= > ==1208677==ERROR: LeakSanitizer: detected memory leaks > > Direct leak of 96 byte(s) in 2 object(s) allocated from: > #0 0x7f93ad4b4a57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 > sonic-net#1 0x7f93ace77233 in qcalloc lib/memory.c:106 > sonic-net#2 0x563bb68f4df1 in process_type5_route bgpd/bgp_evpn.c:5084 > sonic-net#3 0x563bb68fb663 in bgp_nlri_parse_evpn bgpd/bgp_evpn.c:6302 > sonic-net#4 0x563bb69ea2a9 in bgp_nlri_parse bgpd/bgp_packet.c:347 > sonic-net#5 0x563bb69f7716 in bgp_update_receive bgpd/bgp_packet.c:2482 > sonic-net#6 0x563bb6a04d3b in bgp_process_packet bgpd/bgp_packet.c:4091 > sonic-net#7 0x7f93acf8082d in event_call lib/event.c:1996 > sonic-net#8 0x7f93ace48931 in frr_run lib/libfrr.c:1232 > sonic-net#9 0x563bb6880ae1 in main bgpd/bgp_main.c:557 > sonic-net#10 0x7f93ac829d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 Actually, the bgp evpn context may noy be used if adj rib in is unused. This may lead to memory leaks. Fix this by freeing the context in those corner cases. Signed-off-by: Philippe Guibert <[email protected]>
1 parent d84b93f commit 6855bf2

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

bgpd/bgp_route.c

+17-11
Original file line numberDiff line numberDiff line change
@@ -4910,6 +4910,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
49104910
bool force_evpn_import = false;
49114911
safi_t orig_safi = safi;
49124912
struct bgp_labels bgp_labels = {};
4913+
struct bgp_route_evpn *p_evpn = evpn;
49134914
uint8_t i;
49144915

49154916
if (frrtrace_enabled(frr_bgp, process_update)) {
@@ -4951,11 +4952,9 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
49514952
* will not be interned. In which case, it is ok to update the
49524953
* attr->evpn_overlay, so that, this can be stored in adj_in.
49534954
*/
4954-
if (evpn) {
4955-
if (afi == AFI_L2VPN)
4956-
bgp_attr_set_evpn_overlay(attr, evpn);
4957-
else
4958-
evpn_overlay_free(evpn);
4955+
if (evpn && afi == AFI_L2VPN) {
4956+
bgp_attr_set_evpn_overlay(attr, evpn);
4957+
p_evpn = NULL;
49594958
}
49604959
bgp_adj_in_set(dest, peer, attr, addpath_id, &bgp_labels);
49614960
}
@@ -5128,11 +5127,9 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
51285127
* attr->evpn_overlay with evpn directly. Instead memcpy
51295128
* evpn to new_atr.evpn_overlay before it is interned.
51305129
*/
5131-
if (soft_reconfig && evpn) {
5132-
if (afi == AFI_L2VPN)
5133-
bgp_attr_set_evpn_overlay(&new_attr, evpn);
5134-
else
5135-
evpn_overlay_free(evpn);
5130+
if (soft_reconfig && evpn && afi == AFI_L2VPN) {
5131+
bgp_attr_set_evpn_overlay(&new_attr, evpn);
5132+
p_evpn = NULL;
51365133
}
51375134

51385135
/* Apply incoming route-map.
@@ -5301,7 +5298,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
53015298

53025299
bgp_dest_unlock_node(dest);
53035300
bgp_attr_unintern(&attr_new);
5304-
5301+
if (p_evpn)
5302+
evpn_overlay_free(p_evpn);
53055303
return;
53065304
}
53075305

@@ -5466,6 +5464,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
54665464
ret = bgp_damp_update(pi, dest, afi, safi);
54675465
if (ret == BGP_DAMP_SUPPRESSED) {
54685466
bgp_dest_unlock_node(dest);
5467+
if (p_evpn)
5468+
evpn_overlay_free(p_evpn);
54695469
return;
54705470
}
54715471
}
@@ -5552,6 +5552,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
55525552
type, sub_type, NULL);
55535553
}
55545554
#endif
5555+
if (p_evpn)
5556+
evpn_overlay_free(p_evpn);
55555557
return;
55565558
} // End of implicit withdraw
55575559

@@ -5646,6 +5648,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
56465648
}
56475649
#endif
56485650

5651+
if (p_evpn)
5652+
evpn_overlay_free(p_evpn);
56495653
return;
56505654

56515655
/* This BGP update is filtered. Log the reason then update BGP
@@ -5709,6 +5713,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
57095713
}
57105714
#endif
57115715

5716+
if (p_evpn)
5717+
evpn_overlay_free(p_evpn);
57125718
return;
57135719
}
57145720

0 commit comments

Comments
 (0)