From 7d1e1c726da3eb867b5ffc975e9efd91f284bce9 Mon Sep 17 00:00:00 2001 From: Jabber Developer Date: Tue, 24 Jun 2025 15:10:26 +0200 Subject: [PATCH 1/3] fix: Remove unnecessary `theme_init` call (mem leak) Simple `ui_resize` is sufficient for rerendering all the elements. Other calls create complexity, slow down the applications and even introduce mem leaks. `ui_resize` technique is already used widely, including `cmd_editor` case. Fixes #4 --- src/event/server_events.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 20ab28c5..cf25773d 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -156,14 +156,7 @@ sv_ev_roster_received(void) if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) { cons_show_error("Invalid PGP key ID specified: %s, %s", account->pgp_keyid, err_str); } - - // Redraw the screen after entry of the PGP secret key, but not init - ProfWin* win = wins_get_current(); - auto_gchar gchar* theme = prefs_get_string(PREF_THEME); - win_redraw(win); - theme_init(theme); ui_resize(); - ui_show_roster(); } account_free(account); #endif From 83c569de376dc410efb98ad1007ec49fa4bf3586 Mon Sep 17 00:00:00 2001 From: Jabber Developer Date: Tue, 24 Jun 2025 15:24:09 +0200 Subject: [PATCH 2/3] ref: Remove unnecessary variable `bold_items` The variable was introduced in 976e5aa. First used to detect bold characters, it was later replaced by another solution in 850ac3c. --- src/config/theme.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/config/theme.c b/src/config/theme.c index 79afacd1..81b43368 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -58,7 +58,6 @@ static GString* theme_loc; static GKeyFile* theme; -static GHashTable* bold_items; static GHashTable* defaults; static void _load_preferences(void); @@ -78,10 +77,6 @@ _theme_close(void) g_string_free(theme_loc, TRUE); theme_loc = NULL; } - if (bold_items) { - g_hash_table_destroy(bold_items); - bold_items = NULL; - } if (defaults) { g_hash_table_destroy(defaults); defaults = NULL; From d5d5dc5180f60b7ea5980e201a2385e438a10aaa Mon Sep 17 00:00:00 2001 From: Jabber Developer Date: Tue, 24 Jun 2025 15:53:10 +0200 Subject: [PATCH 3/3] ref(theme): ensure clean reinitialization and explicitly initialize static vars Improves code robustness by calling _theme_close() in theme_init() when the theme was already initialized, preventing potential memory leaks or inconsistent state. Closes #4 --- src/config/theme.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/config/theme.c b/src/config/theme.c index 81b43368..70b02b2f 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -56,9 +56,9 @@ #include "config/preferences.h" #include "config/color.h" -static GString* theme_loc; -static GKeyFile* theme; -static GHashTable* defaults; +static GString* theme_loc = NULL; +static GKeyFile* theme = NULL; +static GHashTable* defaults = NULL; static void _load_preferences(void); static void _theme_list_dir(const gchar* const dir, GSList** result); @@ -86,6 +86,12 @@ _theme_close(void) void theme_init(const char* const theme_name) { + if (defaults || theme_loc || theme) { + log_warning("theme_init(): Detected non-NULL state (theme=%p, theme_loc=%p, defaults=%p). Cleaning up previous initialization.", + theme, theme_loc, defaults); + _theme_close(); + } + if (!_theme_load_file(theme_name)) { log_error("Loading theme %s failed.", theme_name);