Skip to content

Commit 7a70d99

Browse files
committed
bgpd : aggregate-address memory leak fix
Memory leaks are observed in the cleanup code. When “no router bgp" is executed, cleanup in that flow for aggregate-address command is not taken care. fixes the below leak: -- ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444:Direct leak of 152 byte(s) in 1 object(s) allocated from: ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- #0 0x7f163e911037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#1 0x7f163e4b9259 in qcalloc lib/memory.c:105 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#2 0x562bf42ebbd5 in bgp_aggregate_new bgpd/bgp_route.c:7239 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#3 0x562bf42f14e8 in bgp_aggregate_set bgpd/bgp_route.c:8421 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#4 0x562bf42f1e55 in aggregate_addressv6_magic bgpd/bgp_route.c:8592 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#5 0x562bf42be3f5 in aggregate_addressv6 bgpd/bgp_route_clippy.c:341 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#6 0x7f163e3f1e1b in cmd_execute_command_real lib/command.c:988 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#7 0x7f163e3f219c in cmd_execute_command lib/command.c:1048 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#8 0x7f163e3f2df4 in cmd_execute lib/command.c:1215 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#9 0x7f163e5a2d73 in vty_command lib/vty.c:544 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#10 0x7f163e5a79c8 in vty_execute lib/vty.c:1307 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#11 0x7f163e5ad299 in vtysh_read lib/vty.c:2216 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#12 0x7f163e593f16 in event_call lib/event.c:1995 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#13 0x7f163e47c839 in frr_run lib/libfrr.c:1185 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#14 0x562bf414e58d in main bgpd/bgp_main.c:505 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#15 0x7f163de66d09 in __libc_start_main ../csu/libc-start.c:308 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444:Direct leak of 152 byte(s) in 1 object(s) allocated from: ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- #0 0x7f163e911037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#1 0x7f163e4b9259 in qcalloc lib/memory.c:105 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#2 0x562bf42ebbd5 in bgp_aggregate_new bgpd/bgp_route.c:7239 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#3 0x562bf42f14e8 in bgp_aggregate_set bgpd/bgp_route.c:8421 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#4 0x562bf42f1cde in aggregate_addressv4_magic bgpd/bgp_route.c:8543 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#5 0x562bf42bd258 in aggregate_addressv4 bgpd/bgp_route_clippy.c:255 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#6 0x7f163e3f1e1b in cmd_execute_command_real lib/command.c:988 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#7 0x7f163e3f219c in cmd_execute_command lib/command.c:1048 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#8 0x7f163e3f2df4 in cmd_execute lib/command.c:1215 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#9 0x7f163e5a2d73 in vty_command lib/vty.c:544 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#10 0x7f163e5a79c8 in vty_execute lib/vty.c:1307 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#11 0x7f163e5ad299 in vtysh_read lib/vty.c:2216 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#12 0x7f163e593f16 in event_call lib/event.c:1995 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#13 0x7f163e47c839 in frr_run lib/libfrr.c:1185 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#14 0x562bf414e58d in main bgpd/bgp_main.c:505 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- sonic-net#15 0x7f163de66d09 in __libc_start_main ../csu/libc-start.c:308 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444- ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.3410444-SUMMARY: AddressSanitizer: 304 byte(s) leaked in 2 allocation(s). Signed-off-by: Samanvitha B Bhargav <[email protected]>
1 parent 6baf6b1 commit 7a70d99

3 files changed

Lines changed: 47 additions & 24 deletions

File tree

bgpd/bgp_route.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8338,30 +8338,7 @@ static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str,
83388338
/* Unlock aggregate address configuration. */
83398339
bgp_dest_set_bgp_aggregate_info(dest, NULL);
83408340

8341-
if (aggregate->community)
8342-
community_free(&aggregate->community);
8343-
8344-
hash_clean_and_free(&aggregate->community_hash,
8345-
bgp_aggr_community_remove);
8346-
8347-
if (aggregate->ecommunity)
8348-
ecommunity_free(&aggregate->ecommunity);
8349-
8350-
hash_clean_and_free(&aggregate->ecommunity_hash,
8351-
bgp_aggr_ecommunity_remove);
8352-
8353-
if (aggregate->lcommunity)
8354-
lcommunity_free(&aggregate->lcommunity);
8355-
8356-
hash_clean_and_free(&aggregate->lcommunity_hash,
8357-
bgp_aggr_lcommunity_remove);
8358-
8359-
if (aggregate->aspath)
8360-
aspath_free(aggregate->aspath);
8361-
8362-
hash_clean_and_free(&aggregate->aspath_hash, bgp_aggr_aspath_remove);
8363-
8364-
bgp_aggregate_free(aggregate);
8341+
bgp_free_aggregate_info(aggregate);
83658342
bgp_dest_unlock_node(dest);
83668343
bgp_dest_unlock_node(dest);
83678344

@@ -8545,6 +8522,34 @@ DEFPY(aggregate_addressv4, aggregate_addressv4_cmd,
85458522
match_med != NULL, suppress_map);
85468523
}
85478524

8525+
void bgp_free_aggregate_info(struct bgp_aggregate *aggregate)
8526+
{
8527+
if (aggregate->community)
8528+
community_free(&aggregate->community);
8529+
8530+
hash_clean_and_free(&aggregate->community_hash,
8531+
bgp_aggr_community_remove);
8532+
8533+
if (aggregate->ecommunity)
8534+
ecommunity_free(&aggregate->ecommunity);
8535+
8536+
hash_clean_and_free(&aggregate->ecommunity_hash,
8537+
bgp_aggr_ecommunity_remove);
8538+
8539+
if (aggregate->lcommunity)
8540+
lcommunity_free(&aggregate->lcommunity);
8541+
8542+
hash_clean_and_free(&aggregate->lcommunity_hash,
8543+
bgp_aggr_lcommunity_remove);
8544+
8545+
if (aggregate->aspath)
8546+
aspath_free(aggregate->aspath);
8547+
8548+
hash_clean_and_free(&aggregate->aspath_hash, bgp_aggr_aspath_remove);
8549+
8550+
bgp_aggregate_free(aggregate);
8551+
}
8552+
85488553
DEFPY(aggregate_addressv6, aggregate_addressv6_cmd,
85498554
"[no] aggregate-address X:X::X:X/M$prefix [{"
85508555
"as-set$as_set_s"

bgpd/bgp_route.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ extern void bgp_process_queue_init(struct bgp *bgp);
661661
extern void bgp_route_init(void);
662662
extern void bgp_route_finish(void);
663663
extern void bgp_cleanup_routes(struct bgp *);
664+
extern void bgp_free_aggregate_info(struct bgp_aggregate *aggregate);
664665
extern void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi,
665666
bool force);
666667
extern void bgp_stop_announce_route_timer(struct peer_af *paf);

bgpd/bgpd.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3844,6 +3844,23 @@ int bgp_delete(struct bgp *bgp)
38443844
#ifdef ENABLE_BGP_VNC
38453845
rfapi_delete(bgp);
38463846
#endif
3847+
3848+
/* Free memory allocated with aggregate address configuration. */
3849+
FOREACH_AFI_SAFI (afi, safi) {
3850+
struct bgp_aggregate *aggregate = NULL;
3851+
3852+
for (struct bgp_dest *dest =
3853+
bgp_table_top(bgp->aggregate[afi][safi]);
3854+
dest; dest = bgp_route_next(dest)) {
3855+
aggregate = bgp_dest_get_bgp_aggregate_info(dest);
3856+
if (aggregate == NULL)
3857+
continue;
3858+
3859+
bgp_dest_set_bgp_aggregate_info(dest, NULL);
3860+
bgp_free_aggregate_info(aggregate);
3861+
}
3862+
}
3863+
38473864
bgp_cleanup_routes(bgp);
38483865

38493866
for (afi = 0; afi < AFI_MAX; ++afi) {

0 commit comments

Comments
 (0)