From bda15542f425bff67b4f821f2e475f4e330696dd Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Wed, 24 Aug 2022 00:02:22 +0200 Subject: [PATCH] bgpd: Fix memory leak when an SRv6 SID is removed 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 SIDs are removed in bgpd: when an SRv6 locator is deleted/unset, all the SIDs allocated from that locator are removed from the SRv6 functions list (`bgp->srv6_functions`),but the memory allocated for the SIDs is not freed. This patch adds a call to `XFREE()` to properly free the allocated memory when an SRv6 SID is removed. 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 c7ef76297a..6488c94075 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -312,8 +312,10 @@ static int bgp_srv6_locator_unset(struct bgp *bgp) } /* refresh functions */ - for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) + for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) { listnode_delete(bgp->srv6_functions, func); + XFREE(MTYPE_BGP_SRV6_FUNCTION, func); + } /* refresh tovpn_sid */ for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) { diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 8a19a1400b..33e8895bec 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -3229,8 +3229,10 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) tmp_prefi.prefixlen = 128; tmp_prefi.prefix = func->sid; if (prefix_match((struct prefix *)&loc.prefix, - (struct prefix *)&tmp_prefi)) + (struct prefix *)&tmp_prefi)) { listnode_delete(bgp->srv6_functions, func); + XFREE(MTYPE_BGP_SRV6_FUNCTION, func); + } } // refresh tovpn_sid