Skip to content

Commit

Permalink
Fix a bunch of obvious memory leaks at termination
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Jaeckel <[email protected]>
  • Loading branch information
sjaeckel committed Jan 8, 2025
1 parent 4d3a948 commit 6794d22
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/command/cmd_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,7 @@ void
cmd_uninit(void)
{
cmd_ac_uninit();
g_hash_table_destroy(commands);
g_hash_table_destroy(search_index);
}

Expand Down
7 changes: 6 additions & 1 deletion src/config/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,18 @@ color_hash(const char* str, color_profile profile)
}

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
Expand Down
2 changes: 2 additions & 0 deletions src/config/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/config/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ theme_list(void)
void
theme_close(void)
{
color_pair_cache_free();
if (theme) {
g_key_file_free(theme);
theme = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/otr/otr.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ otr_shutdown(void)
free(jid);
jid = NULL;
}
otrlib_shutdown();
}

void
Expand Down
1 change: 1 addition & 0 deletions src/otr/otrlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions src/otr/otrlibv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 7 additions & 2 deletions src/ui/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -92,7 +93,7 @@ void
ui_init(void)
{
log_info("Initialising UI");
initscr();
main_scr = initscr();
nonl();
cbreak();
noecho();
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/ui/inputwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ void
inp_close(void)
{
rl_callback_handler_remove();
delwin(inp_win);
fclose(discard);
}

Expand Down
7 changes: 4 additions & 3 deletions src/ui/statusbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -137,6 +135,9 @@ status_bar_close(void)
}
free(statusbar);
}
if (tz) {
g_time_zone_unref(tz);
}
}

void
Expand Down
6 changes: 6 additions & 0 deletions src/ui/titlebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ create_title_bar(void)
inp_put_back();
}

void
free_title_bar(void)
{
delwin(win);
}

void
title_bar_update_virtual(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/ui/titlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/ui/tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ tray_shutdown(void)
}
g_string_free(icon_filename, TRUE);
g_string_free(icon_msg_filename, TRUE);
gtk_main_quit();
}

void
Expand Down
2 changes: 2 additions & 0 deletions src/xmpp/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/xmpp/presence.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/xmpp/presence.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/xmpp/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6794d22

Please sign in to comment.