about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-13 01:01:41 +0000
committerJames Booth <boothj5@gmail.com>2014-11-13 01:01:41 +0000
commit0a7c16747b45c69b9c6e4aa5b384a84197a495f7 (patch)
tree4889403bef1d32ca9a5368db767d0755ff273305
parentada6f5a8b6c9e62728ff1f9a3580a11b11016625 (diff)
downloadprofani-tty-0a7c16747b45c69b9c6e4aa5b384a84197a495f7.tar.gz
Fixed freeing lists
-rw-r--r--src/contact.c13
-rw-r--r--src/ui/core.c21
2 files changed, 18 insertions, 16 deletions
diff --git a/src/contact.c b/src/contact.c
index 144238e7..29c767d8 100644
--- a/src/contact.c
+++ b/src/contact.c
@@ -330,8 +330,19 @@ GList *
 p_contact_get_available_resources(const PContact contact)
 {
     assert(contact != NULL);
+    GList *resources = g_hash_table_get_values(contact->available_resources);
+    GList *ordered = NULL;
+
+    GList *curr_resource = resources;
+    while (curr_resource) {
+        Resource *resource = resources->data;
+        ordered = g_list_insert_sorted(ordered, resource, (GCompareFunc)resource_compare_availability);
+        curr_resource = g_list_next(curr_resource);
+    }
+
+    g_list_free(resources);
 
-    return g_hash_table_get_values(contact->available_resources);
+    return ordered;
 }
 
 gboolean
diff --git a/src/ui/core.c b/src/ui/core.c
index 7fb0a01c..906f4a4b 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -2835,19 +2835,9 @@ _ui_roster_contact(PContact contact)
 
             if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
                 GList *resources = p_contact_get_available_resources(contact);
-                GList *ordered_resources = NULL;
-
-                // sort in order of availabiltiy
-                while (resources != NULL) {
-                    Resource *resource = resources->data;
-                    ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability);
-                    resources = g_list_next(resources);
-                }
-
-                g_list_free(resources);
-
-                while (ordered_resources) {
-                    Resource *resource = ordered_resources->data;
+                GList *curr_resource = resources;
+                while (curr_resource) {
+                    Resource *resource = curr_resource->data;
                     const char *resource_presence = string_from_resource_presence(resource->presence);
                     int resource_presence_colour = win_presence_colour(resource_presence);
                     wattron(window->subwin, resource_presence_colour);
@@ -2859,9 +2849,9 @@ _ui_roster_contact(PContact contact)
 
                     wattroff(window->subwin, resource_presence_colour);
 
-                    ordered_resources = g_list_next(ordered_resources);
+                    curr_resource = g_list_next(curr_resource);
                 }
-                g_list_free(ordered_resources);
+                g_list_free(resources);
             }
         }
     }
@@ -2951,6 +2941,7 @@ _ui_roster(void)
                 _ui_roster_contacts_by_group(curr_group->data);
                 curr_group = g_slist_next(curr_group);
             }
+            g_slist_free_full(groups, free);
             _ui_roster_contacts_by_no_group();
         } else {
             GSList *contacts = roster_get_contacts();