]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Cleanup ctx leak on shutdown and turn off event
authorDonald Sharp <sharpd@nvidia.com>
Fri, 31 Mar 2023 13:08:23 +0000 (09:08 -0400)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Wed, 5 Apr 2023 13:24:47 +0000 (16:24 +0300)
two things:

On shutdown cleanup any events associated with the update walker.
Also do not allow new events to be created.

Fixes this mem-leak:

./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790:Direct leak of 8 byte(s) in 1 object(s) allocated from:
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #0 0x7f0dd0b08037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #1 0x7f0dd06c19f9 in qcalloc lib/memory.c:105
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #2 0x55b42fb605bc in rib_update_ctx_init zebra/zebra_rib.c:4383
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #3 0x55b42fb6088f in rib_update zebra/zebra_rib.c:4421
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #4 0x55b42fa00344 in netlink_link_change zebra/if_netlink.c:2221
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #5 0x55b42fa24622 in netlink_information_fetch zebra/kernel_netlink.c:399
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #6 0x55b42fa28c02 in netlink_parse_info zebra/kernel_netlink.c:1183
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #7 0x55b42fa24951 in kernel_read zebra/kernel_netlink.c:493
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #8 0x7f0dd0797f0c in event_call lib/event.c:1995
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #9 0x7f0dd0684fd9 in frr_run lib/libfrr.c:1185
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #10 0x55b42fa30caa in main zebra/main.c:465
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-    #11 0x7f0dd01b5d09 in __libc_start_main ../csu/libc-start.c:308
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-
./msdp_topo1.test_msdp_topo1/r2.zebra.asan.1117790-SUMMARY: AddressSanitizer: 8 byte(s) leaked in 1 allocation(s).

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 3cd0accb5051e900ab343d5fa7c59360c0c1a812)
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
zebra/main.c
zebra/rib.h
zebra/zebra_rib.c

index 3de97943fd1629581098c6cbef32f9b830a94fe7..3a8aa4cdaf252cf88e47df06cd6906404c606836 100644 (file)
@@ -204,6 +204,8 @@ static void sigint(void)
         */
        zebra_routemap_finish();
 
+       rib_update_finish();
+
        list_delete(&zrouter.client_list);
 
        /* Indicate that all new dplane work has been enqueued. When that
index 99f52bcd4e434070c3ea20ddad4a1a39645df2c7..c9bd2b8c957fbf56e5d2bf17006b3b7bbcd27ed1 100644 (file)
@@ -331,6 +331,7 @@ enum rib_update_event {
        RIB_UPDATE_OTHER,
        RIB_UPDATE_MAX
 };
+void rib_update_finish(void);
 
 int route_entry_update_nhe(struct route_entry *re,
                           struct nhg_hash_entry *new_nhghe);
index adc6a904f1c8ac8ce345698e06c549d2b121c2f5..08391f1a3dfbbdd64217c4fb187a7a008090e806 100644 (file)
@@ -4365,6 +4365,22 @@ static void rib_update_handler(struct thread *thread)
  */
 static struct thread *t_rib_update_threads[RIB_UPDATE_MAX];
 
+void rib_update_finish(void)
+{
+       int i;
+
+       for (i = RIB_UPDATE_KERNEL; i < RIB_UPDATE_MAX; i++) {
+               if (thread_is_scheduled(t_rib_update_threads[i])) {
+                       struct rib_update_ctx *ctx;
+
+                       ctx = THREAD_ARG(t_rib_update_threads[i]);
+
+                       rib_update_ctx_fini(&ctx);
+                       THREAD_OFF(t_rib_update_threads[i]);
+               }
+       }
+}
+
 /* Schedule a RIB update event for all vrfs */
 void rib_update(enum rib_update_event event)
 {
@@ -4373,6 +4389,9 @@ void rib_update(enum rib_update_event event)
        if (thread_is_scheduled(t_rib_update_threads[event]))
                return;
 
+       if (zebra_router_in_shutdown())
+               return;
+
        ctx = rib_update_ctx_init(0, event);
        ctx->vrf_all = true;