about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-01 01:48:36 +0000
committerJames Booth <boothj5@gmail.com>2014-11-01 01:48:36 +0000
commitc4412fe82385945a5a056640135e9b53901d563f (patch)
treea1fc7484b7f692ac436da4a69a027b8cbacf9679
parent51164398e3584e78628197d8c365fd79b16ac103 (diff)
downloadprofani-tty-c4412fe82385945a5a056640135e9b53901d563f.tar.gz
Fixed various memory leaks
-rw-r--r--TODO_0455
-rw-r--r--prof.supp1
-rw-r--r--src/command/command.c5
-rw-r--r--src/command/commands.c7
-rw-r--r--src/ui/console.c1
-rw-r--r--src/ui/core.c2
-rw-r--r--src/ui/window.c2
-rw-r--r--src/xmpp/connection.c6
-rw-r--r--src/xmpp/form.c2
-rw-r--r--src/xmpp/iq.c4
-rw-r--r--src/xmpp/presence.c5
-rw-r--r--src/xmpp/stanza.c5
-rw-r--r--tests/test_cmd_rooms.c18
13 files changed, 47 insertions, 16 deletions
diff --git a/TODO_045 b/TODO_045
index 690dbb2d..72adacdb 100644
--- a/TODO_045
+++ b/TODO_045
@@ -1,4 +1,9 @@
 Test with valgrind using new commands
+    /affiliation
+    /role
+    /occupants
+    /privileges
+    /ping
 
 Update website help
 
diff --git a/prof.supp b/prof.supp
index 084b2cd8..fba137a2 100644
--- a/prof.supp
+++ b/prof.supp
@@ -3,7 +3,6 @@
   Memcheck:Leak
   ...
   fun:_dl_init
-  obj:/lib/x86_64-linux-gnu/ld-2.17.so
   ...
 }
 
diff --git a/src/command/command.c b/src/command/command.c
index 134bdf27..da908c02 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -2348,16 +2348,15 @@ _form_field_autocomplete(char *input, int *size)
             if (((g_strcmp0(split[1], "add") == 0) || (g_strcmp0(split[1], "remove") == 0))
                     && field_type == FIELD_LIST_MULTI) {
                 found = autocomplete_param_with_ac(input, size, beginning->str, value_ac, TRUE);
-                g_string_free(beginning, TRUE);
 
             } else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_TEXT_MULTI) {
                 found = autocomplete_param_with_ac(input, size, beginning->str, value_ac, TRUE);
-                g_string_free(beginning, TRUE);
 
             } else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_JID_MULTI) {
                 found = autocomplete_param_with_ac(input, size, beginning->str, value_ac, TRUE);
-                g_string_free(beginning, TRUE);
             }
+
+            g_string_free(beginning, TRUE);
         }
 
     } else if (g_strv_length(split) == 2) {
diff --git a/src/command/commands.c b/src/command/commands.c
index b8ed63e0..a4808b8a 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2077,15 +2077,15 @@ cmd_form(gchar **args, struct cmd_help_t help)
         iq_submit_room_config(room, current->form);
 
     }
+
     if (g_strcmp0(args[0], "cancel") == 0) {
         iq_room_config_cancel(room);
     }
-    if ((g_strcmp0(args[0], "submit") == 0) ||
-            (g_strcmp0(args[0], "cancel") == 0)) {
+
+    if ((g_strcmp0(args[0], "submit") == 0) || (g_strcmp0(args[0], "cancel") == 0)) {
         if (current->form) {
             cmd_autocomplete_remove_form_fields(current->form);
         }
-
         wins_close_current();
         current = wins_get_by_recipient(room);
         if (current == NULL) {
@@ -2474,6 +2474,7 @@ cmd_rooms(gchar **args, struct cmd_help_t help)
     if (args[0] == NULL) {
         ProfAccount *account = accounts_get_account(jabber_get_account_name());
         iq_room_list_request(account->muc_service);
+        account_free(account);
     } else {
         iq_room_list_request(args[0]);
     }
diff --git a/src/ui/console.c b/src/ui/console.c
index 277a06ce..885dd19d 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -739,6 +739,7 @@ _cons_show_account(ProfAccount *account)
             win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "");
             Jid *jidp = jid_create_from_bare_and_resource(account->jid, resource->name);
             Capabilities *caps = caps_lookup(jidp->fulljid);
+            jid_destroy(jidp);
 
             if (caps != NULL) {
                 // show identity
diff --git a/src/ui/core.c b/src/ui/core.c
index f50ad982..08a1afb8 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -1519,7 +1519,7 @@ _ui_show_room_disco_info(const char * const room, GSList *identities, GSList *fe
                     identity_str = g_string_append(identity_str, identity->category);
                 }
                 win_save_print(window, '!', NULL, 0, 0, "", identity_str->str);
-                g_string_free(identity_str, FALSE);
+                g_string_free(identity_str, TRUE);
                 identities = g_slist_next(identities);
             }
 
diff --git a/src/ui/window.c b/src/ui/window.c
index 43cfdb92..96a71e5e 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -264,6 +264,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
 
     Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick);
     Capabilities *caps = caps_lookup(jidp->fulljid);
+    jid_destroy(jidp);
 
     if (caps) {
         // show identity
@@ -378,6 +379,7 @@ win_show_info(ProfWin *window, PContact contact)
 
         Jid *jidp = jid_create_from_bare_and_resource(barejid, resource->name);
         Capabilities *caps = caps_lookup(jidp->fulljid);
+        jid_destroy(jidp);
 
         if (caps) {
             // show identity
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 6838fb6f..266dd574 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -453,9 +453,9 @@ _connection_handler(xmpp_conn_t * const conn,
             _connection_free_saved_details();
         }
 
-        Jid *myJid = jid_create(jabber_get_fulljid());
-        jabber_conn.domain = strdup(myJid->domainpart);
-        jid_destroy(myJid);
+        Jid *my_jid = jid_create(jabber_get_fulljid());
+        jabber_conn.domain = strdup(my_jid->domainpart);
+        jid_destroy(my_jid);
 
         chat_sessions_init();
 
diff --git a/src/xmpp/form.c b/src/xmpp/form.c
index e4f336e9..9d26b28f 100644
--- a/src/xmpp/form.c
+++ b/src/xmpp/form.c
@@ -458,6 +458,8 @@ _form_tag_exists(DataForm *form, const char * const tag)
         }
         curr = g_list_next(curr);
     }
+
+    g_list_free(tags);
     return FALSE;
 }
 
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index a33f2291..89f0c8ed 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -158,6 +158,8 @@ _iq_disco_info_request(gchar *jid)
 
     xmpp_id_handler_add(conn, _disco_info_response_handler, id, NULL);
 
+    free(id);
+
     xmpp_send(conn, iq);
     xmpp_stanza_release(iq);
 }
@@ -172,6 +174,8 @@ _iq_room_info_request(gchar *room)
 
     xmpp_id_handler_add(conn, _disco_info_response_handler, id, room);
 
+    free(id);
+
     xmpp_send(conn, iq);
     xmpp_stanza_release(iq);
 }
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index 620a871d..8f2230a7 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -373,6 +373,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
 
         log_info("Error joining room: %s, reason: %s", fulljid->barejid, error_cond);
         handle_room_join_error(fulljid->barejid, error_cond);
+        jid_destroy(fulljid);
         return 1;
     }
 
@@ -753,7 +754,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void *
                     handle_leave_room(room);
                 }
 
-                g_slist_free(status_codes);
+                g_slist_free_full(status_codes, free);
             }
 
         // self online
@@ -797,6 +798,8 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void *
                 } else {
                     handle_room_occupant_offline(room, nick, "offline", status_str);
                 }
+
+                g_slist_free_full(status_codes, free);
             }
 
         // room occupant online
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 019f9629..43901ef7 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -113,6 +113,7 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char * const jid,
     xmpp_stanza_set_name(stanza, STANZA_NAME_IQ);
     char *id = create_unique_id("bookmark_add");
     xmpp_stanza_set_id(stanza, id);
+    free(id);
     xmpp_stanza_set_type(stanza, STANZA_TYPE_SET);
 
     xmpp_stanza_t *pubsub = xmpp_stanza_new(ctx);
@@ -1054,6 +1055,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
             if (muc_active(from_jid->barejid)) {
                 char *nick = muc_nick(from_jid->barejid);
                 if (g_strcmp0(from_jid->resourcepart, nick) == 0) {
+                    jid_destroy(from_jid);
                     return TRUE;
                 }
             }
@@ -1065,6 +1067,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
                     char *nick = muc_nick(from_jid->barejid);
                     char *old_nick = muc_old_nick(from_jid->barejid, new_nick);
                     if (g_strcmp0(old_nick, nick) == 0) {
+                        jid_destroy(from_jid);
                         return TRUE;
                     }
                 }
@@ -1090,7 +1093,7 @@ stanza_get_status_codes_by_ns(xmpp_stanza_t * const stanza, char *ns)
             if (g_strcmp0(name, STANZA_NAME_STATUS) == 0) {
                 char *code = xmpp_stanza_get_attribute(child, STANZA_ATTR_CODE);
                 if (code) {
-                    codes = g_slist_append(codes, code);
+                    codes = g_slist_append(codes, strdup(code));
                 }
             }
             child = xmpp_stanza_get_next(child);
diff --git a/tests/test_cmd_rooms.c b/tests/test_cmd_rooms.c
index bbd05471..c2b357a6 100644
--- a/tests/test_cmd_rooms.c
+++ b/tests/test_cmd_rooms.c
@@ -3,6 +3,7 @@
 #include <setjmp.h>
 #include <cmocka.h>
 #include <stdlib.h>
+#include <string.h>
 #include <glib.h>
 
 #include "xmpp/xmpp.h"
@@ -59,9 +60,21 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
 {
     mock_accounts_get_account();
     CommandHelp *help = malloc(sizeof(CommandHelp));
-    ProfAccount *account = malloc(sizeof(ProfAccount));
-    account->muc_service = "default_conf_server";
     gchar *args[] = { NULL };
+    ProfAccount *account = malloc(sizeof(ProfAccount));
+    account->name = NULL;
+    account->jid = NULL;
+    account->password = NULL;
+    account->resource = NULL;
+    account->server = NULL;
+    account->last_presence = NULL;
+    account->login_presence = NULL;
+    account->muc_nick = NULL;
+    account->otr_policy = NULL;
+    account->otr_manual = NULL;
+    account->otr_opportunistic = NULL;
+    account->otr_always = NULL;
+    account->muc_service = strdup("default_conf_server");
 
     mock_connection_status(JABBER_CONNECTED);
     mock_connection_account_name("account_name");
@@ -75,7 +88,6 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
     assert_true(result);
 
     free(help);
-    free(account);
 }
 
 void cmd_rooms_arg_used_when_passed(void **state)