diff options
| author | Donald Sharp <sharpd@nvidia.com> | 2023-11-11 20:31:55 -0500 |
|---|---|---|
| committer | Donald Sharp <sharpd@nvidia.com> | 2023-11-13 09:16:09 -0500 |
| commit | b01738f4d36820f811b680951a6c81f28365558d (patch) | |
| tree | 2c669ddc7e0cc789b5296dee00d93a9c23d0149f | |
| parent | 0e44d248a048cefa646a89fe07aa3607739b0c74 (diff) | |
sharpd: Clean up memory leaks on shutdown
a) The cleanup of zclient on shutdown was not being
done
b) Cleanup vrf shutdown
c) Cleanup some lists
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
sharpd: Cleanup shutdown of vrf and some lists
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
| -rw-r--r-- | sharpd/sharp_main.c | 31 | ||||
| -rw-r--r-- | sharpd/sharp_zebra.c | 14 | ||||
| -rw-r--r-- | sharpd/sharp_zebra.h | 1 |
3 files changed, 36 insertions, 10 deletions
diff --git a/sharpd/sharp_main.c b/sharpd/sharp_main.c index fa85c2b448..0cbed5579d 100644 --- a/sharpd/sharp_main.c +++ b/sharpd/sharp_main.c @@ -54,6 +54,22 @@ struct zebra_privs_t sharp_privs = { struct option longopts[] = {{0}}; +struct sharp_global sg; + +static void sharp_global_init(void) +{ + memset(&sg, 0, sizeof(sg)); + sg.nhs = list_new(); + sg.ted = NULL; + sg.srv6_locators = list_new(); +} + +static void sharp_global_destroy(void) +{ + list_delete(&sg.nhs); + list_delete(&sg.srv6_locators); +} + /* Master of threads. */ struct event_loop *master; @@ -68,6 +84,11 @@ static void sigint(void) { zlog_notice("Terminating on signal"); + vrf_terminate(); + sharp_zebra_terminate(); + + sharp_global_destroy(); + frr_fini(); exit(0); @@ -118,16 +139,6 @@ FRR_DAEMON_INFO(sharpd, SHARP, .vty_port = SHARP_VTY_PORT, .n_yang_modules = array_size(sharpd_yang_modules), ); -struct sharp_global sg; - -static void sharp_global_init(void) -{ - memset(&sg, 0, sizeof(sg)); - sg.nhs = list_new(); - sg.ted = NULL; - sg.srv6_locators = list_new(); -} - static void sharp_start_configuration(void) { zlog_debug("Configuration has started to be read"); diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 30bf4f30e1..fde9f9f544 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -1089,3 +1089,17 @@ void sharp_zebra_init(void) zclient->zebra_connected = zebra_connected; zclient->zebra_buffer_write_ready = sharp_zclient_buffer_ready; } + +void sharp_zebra_terminate(void) +{ + struct sharp_zclient *node = sharp_clients_head; + + while (node) { + sharp_zclient_delete(node->client->session_id); + + node = sharp_clients_head; + } + + zclient_stop(zclient); + zclient_free(zclient); +} diff --git a/sharpd/sharp_zebra.h b/sharpd/sharp_zebra.h index 025b4d8f82..6314f862f5 100644 --- a/sharpd/sharp_zebra.h +++ b/sharpd/sharp_zebra.h @@ -8,6 +8,7 @@ #define __SHARP_ZEBRA_H__ extern void sharp_zebra_init(void); +extern void sharp_zebra_terminate(void); /* Add and delete extra zapi client sessions, for testing */ int sharp_zclient_create(uint32_t session_id); |
