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>
This commit is contained in:
Carmine Scarpitta 2022-08-24 00:02:22 +02:00
parent 03852f673b
commit bda15542f4
2 changed files with 6 additions and 2 deletions

View file

@ -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)) {

View file

@ -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