From 9edf2fe668d1b1d9595042b228c8954b1cd14acb Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 27 Nov 2024 13:10:17 +0100 Subject: [PATCH] Fix a bunch of obvious memory leaks at termination Signed-off-by: Steffen Jaeckel --- src/command/cmd_defs.c | 1 + src/config/color.c | 7 ++++++- src/config/color.h | 2 ++ src/config/theme.c | 1 + src/otr/otr.c | 1 + src/otr/otrlib.h | 1 + src/otr/otrlibv4.c | 6 ++++++ src/ui/core.c | 9 +++++++-- src/ui/inputwin.c | 1 + src/ui/statusbar.c | 7 ++++--- src/ui/titlebar.c | 6 ++++++ src/ui/titlebar.h | 1 + src/ui/tray.c | 1 + src/xmpp/connection.c | 2 ++ src/xmpp/presence.c | 6 ++++++ src/xmpp/presence.h | 1 + src/xmpp/session.c | 2 +- 17 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 48c87059..0253d411 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2882,6 +2882,7 @@ void cmd_uninit(void) { cmd_ac_uninit(); + g_hash_table_destroy(commands); g_hash_table_destroy(search_index); } diff --git a/src/config/color.c b/src/config/color.c index a9e6d697..7a8d0311 100644 --- a/src/config/color.c +++ b/src/config/color.c @@ -430,13 +430,18 @@ out: } void -color_pair_cache_reset(void) +color_pair_cache_free(void) { if (cache.pairs) { free(cache.pairs); memset(&cache, 0, sizeof(cache)); } +} +void +color_pair_cache_reset(void) +{ + color_pair_cache_free(); /* * COLOR_PAIRS is actually not a macro and is thus not a * compile-time constant diff --git a/src/config/color.h b/src/config/color.h index fe0c6e63..b9597375 100644 --- a/src/config/color.h +++ b/src/config/color.h @@ -61,5 +61,7 @@ int color_pair_cache_hash_str(const char* str, color_profile profile); int color_pair_cache_get(const char* pair_name); /* clear cache */ void color_pair_cache_reset(void); +/* free cache */ +void color_pair_cache_free(void); #endif diff --git a/src/config/theme.c b/src/config/theme.c index 88085b36..63940f12 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -251,6 +251,7 @@ theme_list(void) void theme_close(void) { + color_pair_cache_free(); if (theme) { g_key_file_free(theme); theme = NULL; diff --git a/src/otr/otr.c b/src/otr/otr.c index af12b209..cd774f56 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -194,6 +194,7 @@ otr_shutdown(void) free(jid); jid = NULL; } + otrlib_shutdown(); } void diff --git a/src/otr/otrlib.h b/src/otr/otrlib.h index 454013e3..d8d0393b 100644 --- a/src/otr/otrlib.h +++ b/src/otr/otrlib.h @@ -44,6 +44,7 @@ void otrlib_init_ops(OtrlMessageAppOps* ops); void otrlib_init_timer(void); void otrlib_poll(void); +void otrlib_shutdown(void); ConnContext* otrlib_context_find(OtrlUserState user_state, const char* const recipient, char* jid); diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index d735eb74..4d25c703 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -62,6 +62,12 @@ otrlib_init_timer(void) current_interval = otrl_message_poll_get_default_interval(user_state); } +void +otrlib_shutdown(void) +{ + g_timer_destroy(timer); +} + void otrlib_poll(void) { diff --git a/src/ui/core.c b/src/ui/core.c index 8c85070c..e394335d 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -81,6 +81,7 @@ static int inp_size; static gboolean perform_resize = FALSE; static GTimer* ui_idle_time; +static WINDOW* main_scr; #ifdef HAVE_LIBXSS static Display* display; @@ -92,7 +93,7 @@ void ui_init(void) { log_info("Initialising UI"); - initscr(); + main_scr = initscr(); nonl(); cbreak(); noecho(); @@ -182,12 +183,16 @@ ui_reset_idle_time(void) void ui_close(void) { + g_timer_destroy(ui_idle_time); + endwin(); notifier_uninit(); cons_clear_alerts(); wins_destroy(); inp_close(); status_bar_close(); - endwin(); + free_title_bar(); + delwin(main_scr); + delscreen(set_term(NULL)); } void diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index d1d27807..a7e3a138 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -273,6 +273,7 @@ void inp_close(void) { rl_callback_handler_remove(); + delwin(inp_win); fclose(discard); } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 164babca..d60a32e7 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -119,9 +119,7 @@ status_bar_init(void) void status_bar_close(void) { - if (tz) { - g_time_zone_unref(tz); - } + delwin(statusbar_win); if (statusbar) { if (statusbar->time) { g_free(statusbar->time); @@ -137,6 +135,9 @@ status_bar_close(void) } free(statusbar); } + if (tz) { + g_time_zone_unref(tz); + } } void diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 52939a92..55aacbeb 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -85,6 +85,12 @@ create_title_bar(void) inp_put_back(); } +void +free_title_bar(void) +{ + delwin(win); +} + void title_bar_update_virtual(void) { diff --git a/src/ui/titlebar.h b/src/ui/titlebar.h index d2913c99..50408454 100644 --- a/src/ui/titlebar.h +++ b/src/ui/titlebar.h @@ -37,6 +37,7 @@ #define UI_TITLEBAR_H void create_title_bar(void); +void free_title_bar(void); void title_bar_update_virtual(void); void title_bar_resize(void); void title_bar_console(void); diff --git a/src/ui/tray.c b/src/ui/tray.c index 98bd2fdc..0e577f8e 100644 --- a/src/ui/tray.c +++ b/src/ui/tray.c @@ -187,6 +187,7 @@ tray_shutdown(void) } g_string_free(icon_filename, TRUE); g_string_free(icon_msg_filename, TRUE); + gtk_main_quit(); } void diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 0563d60d..c211a609 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -167,6 +167,8 @@ void connection_shutdown(void) { connection_clear_data(); + g_hash_table_destroy(conn.requested_features); + g_hash_table_destroy(conn.available_resources); if (conn.xmpp_conn) { xmpp_conn_release(conn.xmpp_conn); conn.xmpp_conn = NULL; diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 22a91abd..857ac08e 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -83,6 +83,12 @@ presence_sub_requests_init(void) sub_requests_ac = autocomplete_new(); } +void +presence_sub_requests_destroy(void) +{ + autocomplete_free(sub_requests_ac); +} + void presence_handlers_init(void) { diff --git a/src/xmpp/presence.h b/src/xmpp/presence.h index c6810c4e..d00e4580 100644 --- a/src/xmpp/presence.h +++ b/src/xmpp/presence.h @@ -38,6 +38,7 @@ void presence_handlers_init(void); void presence_sub_requests_init(void); +void presence_sub_requests_destroy(void); void presence_clear_sub_requests(void); #endif diff --git a/src/xmpp/session.c b/src/xmpp/session.c index f6d9c93d..e1b4c1a3 100644 --- a/src/xmpp/session.c +++ b/src/xmpp/session.c @@ -233,7 +233,7 @@ session_shutdown(void) _session_free_internals(); chat_sessions_clear(); - presence_clear_sub_requests(); + presence_sub_requests_destroy(); connection_shutdown(); if (saved_status) {