]> git.puffer.fish Git - matthieu/frr.git/commitdiff
sharpd: Fix memory leaks related to SRv6 nexthops
authorCarmine Scarpitta <carmine.scarpitta@uniroma2.it>
Tue, 23 Aug 2022 22:53:19 +0000 (00:53 +0200)
committerCarmine Scarpitta <carmine.scarpitta@uniroma2.it>
Wed, 24 Aug 2022 12:22:04 +0000 (14:22 +0200)
Running the `zebra_seg6local_route` topotest with `--valgrind-memleaks`
gives several memory leak errors. This is due to the way SRv6 routes
(seg6 and seg6local routes) are handled: when the user executes the CLI
command `sharp install seg6-routes` or `sharp install seg6local-routes`
to create a seg6 or seg6local route, sharpd calls
`nexthop_add_srv6_seg6` or `nexthop_add_srv6_seg6local` to create an
SRv6 nexthop. A pointer to the SRv6 nexthop is stored in the global data
structure `sg.r.nhop`. If you call `sharp install routes`,
`sharp install seg6-routes` or `sharp install seg6local-routes` to create
more routes, `sg.r.nhop` is set to zero and the
pointer to the SRv6 nexthop contained in `sg.r.nhop` is definitely lost
and the allocated memory is never freed.

This patch adds calls to `nexthop_del_srv6_seg6()` and
`nexthop_del_srv6_seg6local()` to free the memory allocated for the SRv6
nexthop before clearing the `sg.r.nhop` data structure.

Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
sharpd/sharp_vty.c

index cfde0749b1f04d40b48de94d9b28314c41794064..3853df7cb08a1b4d754cd29bc183c5140e794645 100644 (file)
@@ -234,6 +234,8 @@ DEFPY (install_routes,
 
        memset(&prefix, 0, sizeof(prefix));
        memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
+       nexthop_del_srv6_seg6local(&sg.r.nhop);
+       nexthop_del_srv6_seg6(&sg.r.nhop);
        memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
        memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
        memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
@@ -376,6 +378,8 @@ DEFPY (install_seg6_routes,
 
        memset(&prefix, 0, sizeof(prefix));
        memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
+       nexthop_del_srv6_seg6local(&sg.r.nhop);
+       nexthop_del_srv6_seg6(&sg.r.nhop);
        memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
        memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
        memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
@@ -467,6 +471,8 @@ DEFPY (install_seg6local_routes,
                sg.r.repeat = 0;
 
        memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
+       nexthop_del_srv6_seg6local(&sg.r.nhop);
+       nexthop_del_srv6_seg6(&sg.r.nhop);
        memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
        memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
        memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));