From 0a7c16747b45c69b9c6e4aa5b384a84197a495f7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 13 Nov 2014 01:01:41 +0000 Subject: Fixed freeing lists --- src/contact.c | 13 ++++++++++++- src/ui/core.c | 21 ++++++--------------- 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(); -- cgit 1.4.1-2-gfad0