diff options
| author | Carmine Scarpitta <carmine.scarpitta@uniroma2.it> | 2022-08-24 00:02:22 +0200 |
|---|---|---|
| committer | Carmine Scarpitta <carmine.scarpitta@uniroma2.it> | 2022-08-24 08:56:46 +0200 |
| commit | bda15542f425bff67b4f821f2e475f4e330696dd (patch) | |
| tree | 60a3e6bd76d8b0a000dfae577587bf8c14ef202c | |
| parent | 03852f673b571fc7f5d815a3f00429533f38d2aa (diff) | |
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 <carmine.scarpitta@uniroma2.it>
| -rw-r--r-- | bgpd/bgp_vty.c | 4 | ||||
| -rw-r--r-- | 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 |
