From 0e42e319d53ed3a4ffed4fc074f486974b4a4f7e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 21 May 2018 20:13:27 -0400 Subject: [PATCH] bgpd: Fix crash when shutdown The process of BGP shutdown hard free's memory irrelevant to the fact that another process may be using that memory still in route leaking scenario's. As a temporary fix find the default instance and free it last. Ticket: CM-21068 Signed-off-by: Donald Sharp --- bgpd/bgp_main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index acb4272cd1..1740f3d1db 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -168,7 +168,7 @@ void sigusr1(void) */ static __attribute__((__noreturn__)) void bgp_exit(int status) { - struct bgp *bgp; + struct bgp *bgp, *bgp_default; struct listnode *node, *nnode; /* it only makes sense for this to be called on a clean exit */ @@ -180,9 +180,15 @@ static __attribute__((__noreturn__)) void bgp_exit(int status) bgp_close(); + bgp_default = bgp_get_default(); + /* reverse bgp_master_init */ - for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) + for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) { + if (bgp_default == bgp) + continue; bgp_delete(bgp); + } + bgp_delete(bgp_default); /* reverse bgp_dump_init */ bgp_dump_finish();