about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/config/accounts.c14
-rw-r--r--src/contact.c34
-rw-r--r--src/jid.c14
-rw-r--r--src/muc.c20
-rw-r--r--src/resource.c11
-rw-r--r--src/tools/autocomplete.c6
-rw-r--r--src/ui/console.c2
-rw-r--r--src/ui/core.c5
-rw-r--r--src/xmpp/capabilities.c17
-rw-r--r--src/xmpp/presence.c26
-rw-r--r--src/xmpp/stanza.c8
11 files changed, 72 insertions, 85 deletions
diff --git a/src/config/accounts.c b/src/config/accounts.c
index 876ff870..c82f6b2d 100644
--- a/src/config/accounts.c
+++ b/src/config/accounts.c
@@ -236,13 +236,13 @@ void
 accounts_free_account(ProfAccount *account)
 {
     if (account != NULL) {
-        FREE_SET_NULL(account->name);
-        FREE_SET_NULL(account->jid);
-        FREE_SET_NULL(account->resource);
-        FREE_SET_NULL(account->server);
-        FREE_SET_NULL(account->last_presence);
-        FREE_SET_NULL(account->login_presence);
-        FREE_SET_NULL(account);
+        free(account->name);
+        free(account->jid);
+        free(account->resource);
+        free(account->server);
+        free(account->last_presence);
+        free(account->login_presence);
+        free(account);
     }
 }
 
diff --git a/src/contact.c b/src/contact.c
index 44cbd4b4..1b566d40 100644
--- a/src/contact.c
+++ b/src/contact.c
@@ -79,14 +79,9 @@ p_contact_new(const char * const barejid, const char * const name,
 void
 p_contact_set_name(const PContact contact, const char * const name)
 {
-    if (contact->name != NULL) {
-        FREE_SET_NULL(contact->name);
-    }
-
+    FREE_SET_NULL(contact->name);
     if (name != NULL) {
         contact->name = strdup(name);
-    } else {
-        FREE_SET_NULL(contact->name);
     }
 }
 
@@ -130,22 +125,23 @@ p_contact_remove_resource(PContact contact, const char * const resource)
 void
 p_contact_free(PContact contact)
 {
-    FREE_SET_NULL(contact->barejid);
-    FREE_SET_NULL(contact->name);
-    FREE_SET_NULL(contact->subscription);
-    FREE_SET_NULL(contact->offline_message);
+    if (contact != NULL) {
+        free(contact->barejid);
+        free(contact->name);
+        free(contact->subscription);
+        free(contact->offline_message);
+
+        if (contact->groups != NULL) {
+            g_slist_free_full(contact->groups, g_free);
+        }
 
-    if (contact->groups != NULL) {
-        g_slist_free_full(contact->groups, g_free);
-    }
+        if (contact->last_activity != NULL) {
+            g_date_time_unref(contact->last_activity);
+        }
 
-    if (contact->last_activity != NULL) {
-        g_date_time_unref(contact->last_activity);
+        g_hash_table_destroy(contact->available_resources);
+        free(contact);
     }
-
-    g_hash_table_destroy(contact->available_resources);
-
-    FREE_SET_NULL(contact);
 }
 
 const char *
diff --git a/src/jid.c b/src/jid.c
index b236c164..6840b64b 100644
--- a/src/jid.c
+++ b/src/jid.c
@@ -108,13 +108,13 @@ void
 jid_destroy(Jid *jid)
 {
     if (jid != NULL) {
-        GFREE_SET_NULL(jid->str);
-        GFREE_SET_NULL(jid->localpart);
-        GFREE_SET_NULL(jid->domainpart);
-        GFREE_SET_NULL(jid->resourcepart);
-        GFREE_SET_NULL(jid->barejid);
-        GFREE_SET_NULL(jid->fulljid);
-        FREE_SET_NULL(jid);
+        g_free(jid->str);
+        g_free(jid->localpart);
+        g_free(jid->domainpart);
+        g_free(jid->resourcepart);
+        g_free(jid->barejid);
+        g_free(jid->fulljid);
+        free(jid);
     }
 }
 
diff --git a/src/muc.c b/src/muc.c
index 464d3e1b..1e706f6a 100644
--- a/src/muc.c
+++ b/src/muc.c
@@ -442,32 +442,20 @@ static void
 _free_room(ChatRoom *room)
 {
     if (room != NULL) {
-        if (room->room != NULL) {
-            g_free(room->room);
-            room->room = NULL;
-        }
-        if (room->nick != NULL) {
-            g_free(room->nick);
-            room->nick = NULL;
-        }
-        if (room->subject != NULL) {
-            g_free(room->subject);
-            room->subject = NULL;
-        }
+        free(room->room);
+        free(room->nick);
+        free(room->subject);
         if (room->roster != NULL) {
             g_hash_table_remove_all(room->roster);
-            room->roster = NULL;
         }
         if (room->nick_ac != NULL) {
             autocomplete_free(room->nick_ac);
         }
         if (room->nick_changes != NULL) {
             g_hash_table_remove_all(room->nick_changes);
-            room->nick_changes = NULL;
         }
-        g_free(room);
+        free(room);
     }
-    room = NULL;
 }
 
 static
diff --git a/src/resource.c b/src/resource.c
index 0a7838f3..86ba7e18 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -81,9 +81,10 @@ resource_compare_availability(Resource *first, Resource *second)
 
 void resource_destroy(Resource *resource)
 {
-    assert(resource != NULL);
-    FREE_SET_NULL(resource->name);
-    FREE_SET_NULL(resource->status);
-    FREE_SET_NULL(resource->caps_str);
-    FREE_SET_NULL(resource);
+    if (resource != NULL) {
+        free(resource->name);
+        free(resource->status);
+        free(resource->caps_str);
+        free(resource);
+    }
 }
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c
index 8426de85..5c70f874 100644
--- a/src/tools/autocomplete.c
+++ b/src/tools/autocomplete.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "common.h"
 #include "tools/autocomplete.h"
 #include "tools/parser.h"
 
@@ -59,10 +60,7 @@ void
 autocomplete_reset(Autocomplete ac)
 {
     ac->last_found = NULL;
-    if (ac->search_str != NULL) {
-        free(ac->search_str);
-        ac->search_str = NULL;
-    }
+    FREE_SET_NULL(ac->search_str);
 }
 
 void
diff --git a/src/ui/console.c b/src/ui/console.c
index 50d2b649..6efc1cf1 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -784,7 +784,7 @@ cons_show_room_invite(const char * const invitor, const char * const room,
         notify_invite(display_from, room, reason);
     }
 
-    FREE_SET_NULL(display_from);
+    free(display_from);
 
     ui_console_dirty();
     cons_alert();
diff --git a/src/ui/core.c b/src/ui/core.c
index 126fe127..6b0b2d8d 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -293,8 +293,9 @@ ui_incoming_msg(const char * const from, const char * const message,
     GTimeVal *tv_stamp, gboolean priv)
 {
     gboolean win_created = FALSE;
-    char *display_from;
+    char *display_from = NULL;
     win_type_t win_type;
+
     if (priv) {
         win_type = WIN_PRIVATE;
         display_from = get_nick_from_full_jid(from);
@@ -436,7 +437,7 @@ ui_incoming_msg(const char * const from, const char * const message,
     if (prefs_get_boolean(PREF_NOTIFY_MESSAGE))
         notify_message(display_from, ui_index);
 
-    FREE_SET_NULL(display_from);
+    free(display_from);
 }
 
 void
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c
index 10aa8a38..f9624f90 100644
--- a/src/xmpp/capabilities.c
+++ b/src/xmpp/capabilities.c
@@ -301,17 +301,16 @@ static void
 _caps_destroy(Capabilities *caps)
 {
     if (caps != NULL) {
-        FREE_SET_NULL(caps->category);
-        FREE_SET_NULL(caps->type);
-        FREE_SET_NULL(caps->name);
-        FREE_SET_NULL(caps->software);
-        FREE_SET_NULL(caps->software_version);
-        FREE_SET_NULL(caps->os);
-        FREE_SET_NULL(caps->os_version);
+        free(caps->category);
+        free(caps->type);
+        free(caps->name);
+        free(caps->software);
+        free(caps->software_version);
+        free(caps->os);
+        free(caps->os_version);
         if (caps->features != NULL) {
             g_slist_free_full(caps->features, free);
-            caps->features = NULL;
         }
-        FREE_SET_NULL(caps);
+        free(caps);
     }
 }
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index f072196d..6c87a8ac 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -385,7 +385,7 @@ _unavailable_handler(xmpp_conn_t * const conn,
         }
     }
 
-    FREE_SET_NULL(status_str);
+    free(status_str);
     jid_destroy(my_jid);
     jid_destroy(from_jid);
 
@@ -471,8 +471,8 @@ _available_handler(xmpp_conn_t * const conn,
             last_activity);
     }
 
-    FREE_SET_NULL(status_str);
-    FREE_SET_NULL(show_str);
+    free(status_str);
+    free(show_str);
     jid_destroy(my_jid);
     jid_destroy(from_jid);
 
@@ -556,10 +556,11 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
         return 1;
     }
 
-    const char *jid = xmpp_conn_get_jid(conn);
     char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
-    Jid *my_jid = jid_create(jid);
     Jid *from_jid = jid_create(from);
+    if (from_jid == NULL || from_jid->resourcepart == NULL) {
+        return 1;
+    }
 
     char *room = from_jid->barejid;
     char *nick = from_jid->resourcepart;
@@ -592,7 +593,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     // handle presence from room members
     } else {
         char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
-        char *show_str, *status_str;
+        char *status_str;
 
         char *caps_key = NULL;
         if (stanza_contains_caps(stanza)) {
@@ -608,12 +609,15 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
             // handle nickname change
             if (stanza_is_room_nick_change(stanza)) {
                 char *new_nick = stanza_get_new_nick(stanza);
-                muc_set_roster_pending_nick_change(room, new_nick, nick);
+                if (new_nick != NULL) {
+                    muc_set_roster_pending_nick_change(room, new_nick, nick);
+                    free(new_nick);
+                }
             } else {
                 prof_handle_room_member_offline(room, nick, "offline", status_str);
             }
         } else {
-            show_str = stanza_get_show(stanza, "online");
+            char *show_str = stanza_get_show(stanza, "online");
             if (!muc_get_roster_received(room)) {
                 muc_add_to_roster(room, nick, show_str, status_str, caps_key);
             } else {
@@ -631,13 +635,13 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
                 }
             }
 
-           FREE_SET_NULL(show_str);
+           free(show_str);
         }
 
-        FREE_SET_NULL(status_str);
+        free(status_str);
+        free(caps_key);
     }
 
-    jid_destroy(my_jid);
     jid_destroy(from_jid);
 
     return 1;
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 4d7d1f9d..61db0537 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -140,7 +140,7 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
         xmpp_stanza_set_name(chat_state, state);
         xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
         xmpp_stanza_add_child(msg, chat_state);
-	xmpp_stanza_release(chat_state);
+        xmpp_stanza_release(chat_state);
     }
 
     return msg;
@@ -840,12 +840,11 @@ void
 stanza_destroy_form(DataForm *form)
 {
     if (form != NULL) {
-        FREE_SET_NULL(form->form_type);
         if (form->fields != NULL) {
             GSList *curr_field = form->fields;
             while (curr_field != NULL) {
                 FormField *field = curr_field->data;
-                FREE_SET_NULL(field->var);
+                free(field->var);
                 if ((field->values) != NULL) {
                     g_slist_free_full(field->values, free);
                 }
@@ -854,6 +853,7 @@ stanza_destroy_form(DataForm *form)
             g_slist_free_full(form->fields, free);
         }
 
+        free(form->form_type);
         free(form);
     }
 }
@@ -941,7 +941,7 @@ stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence)
     xmpp_stanza_add_child(presence, caps);
     xmpp_stanza_release(caps);
     xmpp_stanza_release(query);
-    FREE_SET_NULL(sha1);
+    g_free(sha1);
 }
 
 const char *