about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-06-17 22:22:35 +0100
committerJames Booth <boothj5@gmail.com>2014-06-17 22:22:35 +0100
commit4a485a64f9a09c1b19c59af3d03e2c2c2d62d398 (patch)
tree84f68392ac94f9d43b709b8d718922e8273358ce
parentfa0be4e50ed8be0cd1fc8bb9fa2e0c1885998770 (diff)
downloadprofani-tty-4a485a64f9a09c1b19c59af3d03e2c2c2d62d398.tar.gz
Free account_name preference on autoconnect
-rw-r--r--src/config/preferences.c2
-rw-r--r--src/profanity.c18
2 files changed, 12 insertions, 8 deletions
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 7acd5a0d..335915aa 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -171,7 +171,7 @@ prefs_get_string(preference_t pref)
     char *result = g_key_file_get_string(prefs, group, key, NULL);
 
     if (result == NULL) {
-        return def;
+        return strdup(def);
     } else {
         return result;
     }
diff --git a/src/profanity.c b/src/profanity.c
index 209289e2..f99f90c3 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -72,14 +72,18 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
 
     ui_update_screen();
 
+    char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT);
     if (account_name != NULL) {
-      char *cmd = "/connect";
-      snprintf(inp, sizeof(inp), "%s %s", cmd, account_name);
-      process_input(inp);
-    } else if (prefs_get_string(PREF_CONNECT_ACCOUNT) != NULL) {
-      char *cmd = "/connect";
-      snprintf(inp, sizeof(inp), "%s %s", cmd, prefs_get_string(PREF_CONNECT_ACCOUNT));
-      process_input(inp);
+        char *cmd = "/connect";
+        snprintf(inp, sizeof(inp), "%s %s", cmd, account_name);
+        process_input(inp);
+    } else if (pref_connect_account != NULL) {
+        char *cmd = "/connect";
+        snprintf(inp, sizeof(inp), "%s %s", cmd, pref_connect_account);
+        process_input(inp);
+    }
+    if (pref_connect_account != NULL) {
+        free(pref_connect_account);
     }
 
     while(cmd_result == TRUE) {