]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Fix memory leak in SRv6 locator delete/unset
authorCarmine Scarpitta <carmine.scarpitta@uniroma2.it>
Tue, 23 Aug 2022 21:55:05 +0000 (23:55 +0200)
committerCarmine Scarpitta <carmine.scarpitta@uniroma2.it>
Wed, 24 Aug 2022 06:53:08 +0000 (08:53 +0200)
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 <carmine.scarpitta@uniroma2.it>
bgpd/bgp_vty.c
bgpd/bgp_zebra.c

index 0eba5ea4479ad6de6ffd3da20c9094e9e73ee54a..c7ef76297a629f89264795e04d9180cd48a7b73f 100644 (file)
@@ -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))
index 9c9b88e1255420d7ca144496ab5b1d51472d7ac3..8a19a1400b546fee01de406c51b9001da990c0bb 100644 (file)
@@ -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)) {