about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-06-17 23:34:52 +0100
committerJames Booth <boothj5@gmail.com>2014-06-17 23:34:52 +0100
commit79ddf1048486d1a77a1aee9b8152c8ffb25d8a11 (patch)
treeae96e2efee1116f006b2c77137e87efabd73f0c3
parentad68bcfde2d606906242f265a661ea3690e145bd (diff)
downloadprofani-tty-79ddf1048486d1a77a1aee9b8152c8ffb25d8a11.tar.gz
Fixed memleaks with otr policy and autoaway options
-rw-r--r--src/command/command.c5
-rw-r--r--src/command/commands.c1
-rw-r--r--src/otr/otr.c8
-rw-r--r--src/profanity.c20
-rw-r--r--src/server_events.c2
5 files changed, 25 insertions, 11 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 5556fd7c..611ce7db 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -1413,10 +1413,13 @@ cmd_execute_default(const char * const inp)
                 ui_current_print_line("You are not currently connected.");
             } else {
 #ifdef HAVE_LIBOTR
-                if ((strcmp(otr_get_policy(recipient), "always") == 0) && !otr_is_secure(recipient)) {
+                char *policy = otr_get_policy(recipient);
+                if ((strcmp(policy, "always") == 0) && !otr_is_secure(recipient)) {
                     cons_show_error("Failed to send message. Please check OTR policy");
+                    free(policy);
                     return TRUE;
                 }
+                free(policy);
                 if (otr_is_secure(recipient)) {
                     char *encrypted = otr_encrypt_message(recipient, inp);
                     if (encrypted != NULL) {
diff --git a/src/command/commands.c b/src/command/commands.c
index cf9dec11..aae32cb6 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1033,6 +1033,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
                     message_send(msg, usr_jid);
                 }
                 ui_outgoing_msg("me", usr_jid, msg);
+                free(policy);
 
                 if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
                     const char *jid = jabber_get_fulljid();
diff --git a/src/otr/otr.c b/src/otr/otr.c
index 501c7583..7a5733bf 100644
--- a/src/otr/otr.c
+++ b/src/otr/otr.c
@@ -527,15 +527,15 @@ _otr_get_policy(const char * const recipient)
     // check contact specific setting
     if (g_list_find_custom(account->otr_manual, recipient, (GCompareFunc)g_strcmp0)) {
         account_free(account);
-        return "manual";
+        return strdup("manual");
     }
     if (g_list_find_custom(account->otr_opportunistic, recipient, (GCompareFunc)g_strcmp0)) {
         account_free(account);
-        return "opportunistic";
+        return strdup("opportunistic");
     }
     if (g_list_find_custom(account->otr_always, recipient, (GCompareFunc)g_strcmp0)) {
         account_free(account);
-        return "always";
+        return strdup("always");
     }
 
     // check default account setting
@@ -551,7 +551,7 @@ _otr_get_policy(const char * const recipient)
             result = "always";
         }
         account_free(account);
-        return result;
+        return strdup(result);
     }
     account_free(account);
 
diff --git a/src/profanity.c b/src/profanity.c
index f99f90c3..899e70c4 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -219,6 +219,8 @@ _handle_idle_time()
     gint prefs_time = prefs_get_autoaway_time() * 60000;
     resource_presence_t current_presence = accounts_get_last_presence(jabber_get_account_name());
     unsigned long idle_ms = ui_get_idle_time();
+    char *pref_autoaway_mode = prefs_get_string(PREF_AUTOAWAY_MODE);
+    char *pref_autoaway_message = prefs_get_string(PREF_AUTOAWAY_MESSAGE);
 
     if (!idle) {
         if ((current_presence == RESOURCE_ONLINE) || (current_presence == RESOURCE_CHAT)) {
@@ -226,13 +228,13 @@ _handle_idle_time()
                 idle = TRUE;
 
                 // handle away mode
-                if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) {
-                    presence_update(RESOURCE_AWAY, prefs_get_string(PREF_AUTOAWAY_MESSAGE), 0);
+                if (strcmp(pref_autoaway_mode, "away") == 0) {
+                    presence_update(RESOURCE_AWAY, pref_autoaway_message, 0);
                     ui_auto_away();
 
                 // handle idle mode
-                } else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) {
-                    presence_update(RESOURCE_ONLINE, prefs_get_string(PREF_AUTOAWAY_MESSAGE), idle_ms / 1000);
+                } else if (strcmp(pref_autoaway_mode, "idle") == 0) {
+                    presence_update(RESOURCE_ONLINE, pref_autoaway_message, idle_ms / 1000);
                 }
             }
         }
@@ -243,16 +245,22 @@ _handle_idle_time()
 
             // handle check
             if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) {
-                if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "away") == 0) {
+                if (strcmp(pref_autoaway_mode, "away") == 0) {
                     presence_update(RESOURCE_ONLINE, NULL, 0);
                     ui_end_auto_away();
-                } else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) {
+                } else if (strcmp(pref_autoaway_mode, "idle") == 0) {
                     presence_update(RESOURCE_ONLINE, NULL, 0);
                     ui_titlebar_presence(CONTACT_ONLINE);
                 }
             }
         }
     }
+    if (pref_autoaway_mode != NULL) {
+        free(pref_autoaway_mode);
+    }
+    if (pref_autoaway_message != NULL) {
+        free(pref_autoaway_message);
+    }
 }
 
 static void
diff --git a/src/server_events.c b/src/server_events.c
index ecd1ff57..7182af87 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -254,6 +254,7 @@ handle_incoming_message(char *from, char *message, gboolean priv)
 
         // internal OTR message
         if (newmessage == NULL) {
+            free(policy);
             return;
         }
     } else {
@@ -264,6 +265,7 @@ handle_incoming_message(char *from, char *message, gboolean priv)
         cons_show("Attempting to start OTR session...");
         message_send(otr_query_message, from);
     }
+    free(policy);
 
     ui_incoming_msg(from, newmessage, NULL, priv);