about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorDmitry Podgorny <pasis.ua@gmail.com>2020-02-27 01:35:36 +0200
committerDmitry Podgorny <pasis.ua@gmail.com>2020-02-27 01:35:36 +0200
commitd18ec23d0a38bd538d48f7e827fec0fceb9f230d (patch)
tree5b1284d4c35cf121af9aa8670fbc7b31177fd862 /src/config
parent779c2efc1710ed5d8b4fa60e00e85731b7bb7bd7 (diff)
downloadprofani-tty-d18ec23d0a38bd538d48f7e827fec0fceb9f230d.tar.gz
Fix few memory leaks
Diffstat (limited to 'src/config')
-rw-r--r--src/config/preferences.c21
1 files changed, 17 insertions, 4 deletions
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;