diff --git a/src/config/preferences.c b/src/config/preferences.c index fdd18ea0..589a6c92 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -80,7 +80,7 @@ static const char* _get_key(preference_t pref); static gboolean _get_default_boolean(preference_t pref); static char* _get_default_string(preference_t pref); -void _prefs_load(void) +static void _prefs_load(void) { GError *err = NULL; log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err); @@ -166,9 +166,23 @@ void _prefs_load(void) g_strfreev(triggers); } +/* Clean up after _prefs_load() */ +static void _prefs_close(void) +{ + autocomplete_free(boolean_choice_ac); + autocomplete_free(room_trigger_ac); +} + void prefs_reload(void) { + /* + * Current function contains copy-paste, but we wanted to avoid config_file + * manipulation from prefs_load/prefs_close + */ + + _prefs_close(); + g_key_file_free(prefs); prefs = NULL; @@ -185,7 +199,7 @@ prefs_load(char *config_file) if (config_file == NULL) { prefs_loc = files_get_config_path(FILE_PROFRC); } else { - prefs_loc = config_file; + prefs_loc = strdup(config_file); } if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) { @@ -207,8 +221,7 @@ prefs_save(void) void prefs_close(void) { - autocomplete_free(boolean_choice_ac); - autocomplete_free(room_trigger_ac); + _prefs_close(); g_key_file_free(prefs); prefs = NULL; diff --git a/src/main.c b/src/main.c index 33367743..99ccfbc0 100644 --- a/src/main.c +++ b/src/main.c @@ -60,7 +60,7 @@ #include "command/cmd_defs.h" static gboolean version = FALSE; -static char *log = "INFO"; +static char *log = NULL; static char *log_file = NULL; static char *account_name = NULL; static char *config_file = NULL; @@ -175,7 +175,17 @@ main(int argc, char **argv) return 0; } - prof_run(log, account_name, config_file, log_file); + prof_run(log ? log : "INFO", account_name, config_file, log_file); + + /* Free resources allocated by GOptionContext */ + if (log) + g_free(log); + if (account_name) + g_free(account_name); + if (config_file) + g_free(config_file); + if (log_file) + g_free(log_file); return 0; } diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 3104aa6c..02f59b3f 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -252,6 +252,7 @@ iq_handlers_clear() { if (id_handlers) { g_hash_table_remove_all(id_handlers); + g_hash_table_destroy(id_handlers); id_handlers = NULL; } } @@ -340,6 +341,7 @@ iq_rooms_cache_clear(void) { if (rooms_cache) { g_hash_table_remove_all(rooms_cache); + g_hash_table_destroy(rooms_cache); rooms_cache = NULL; } }