From 03852f673b571fc7f5d815a3f00429533f38d2aa Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Tue, 23 Aug 2022 23:55:05 +0200 Subject: [PATCH] bgpd: Fix memory leak in SRv6 locator delete/unset Running `bgp_srv6l3vpn_to_bgp_vrf` and `bgp_srv6l3vpn_to_bgp_vrf2` topotests with `--valgrind-memleaks` gives several memory leak errors. This is due to the way SRv6 locators are deleted/unset in bgpd: when an SRv6 locator is deleted/unset, all the chunks of the locator are removed from the SRv6 locator chunks list (`bgp->srv6_locator_chunks`). However, the memory allocated for the chunks is not freed. This patch adds a call to the `srv6_locator_chunk_free()` function to properly free the allocated memory when an SRv6 locator is removed or unset. Signed-off-by: Carmine Scarpitta --- bgpd/bgp_vty.c | 4 +++- bgpd/bgp_zebra.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 0eba5ea447..c7ef76297a 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -306,8 +306,10 @@ static int bgp_srv6_locator_unset(struct bgp *bgp) return -1; /* refresh chunks */ - for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) + for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) { listnode_delete(bgp->srv6_locator_chunks, chunk); + srv6_locator_chunk_free(chunk); + } /* refresh functions */ for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 9c9b88e125..8a19a1400b 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -3218,8 +3218,10 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) // refresh chunks for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) if (prefix_match((struct prefix *)&loc.prefix, - (struct prefix *)&chunk->prefix)) + (struct prefix *)&chunk->prefix)) { listnode_delete(bgp->srv6_locator_chunks, chunk); + srv6_locator_chunk_free(chunk); + } // refresh functions for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) { -- 2.39.5