From 3292693b2feaad34d978c4f0ec43a2eb9d0c825c Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 30 May 2018 17:51:29 -0400 Subject: [PATCH] bgpd: Cleanup leaked memory on shutdown When we are shutting down, there exists a code path where the connected table leaks some memory. Cleanup the code to remove the memory. Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 0cb9bc7e2b..fd8d894878 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -364,6 +364,22 @@ void bgp_connected_delete(struct bgp *bgp, struct connected *ifc) bgp_unlock_node(rn); } +static void bgp_connected_cleanup(struct route_table *table, + struct route_node *rn) +{ + struct bgp_connected_ref *bc; + + bc = rn->info; + if (!bc) + return; + + bc->refcnt--; + if (bc->refcnt == 0) { + XFREE(MTYPE_BGP_CONN, bc); + rn->info = NULL; + } +} + int bgp_nexthop_self(struct bgp *bgp, struct in_addr nh_addr) { struct bgp_addr tmp, *addr; @@ -643,6 +659,8 @@ void bgp_scan_finish(struct bgp *bgp) bgp_table_unlock(bgp->nexthop_cache_table[afi]); bgp->nexthop_cache_table[afi] = NULL; + bgp->connected_table[afi]->route_table->cleanup = + bgp_connected_cleanup; bgp_table_unlock(bgp->connected_table[afi]); bgp->connected_table[afi] = NULL; -- 2.39.5