about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-02-10 20:47:22 +0000
committerJames Booth <boothj5@gmail.com>2015-02-10 20:47:22 +0000
commit13297a151f0612516bcff643ff618bb28b64ddf1 (patch)
treeb49e2334c29f71b48c88d70cc85ebc51c49ec63d /src
parent64774a947edf87f6acae07305861149f5194052b (diff)
parent6ab937c3e37b71315ab8661c6188ded49dfa182b (diff)
downloadprofani-tty-13297a151f0612516bcff643ff618bb28b64ddf1.tar.gz
Merge branch 'master' into readline
Conflicts:
	src/ui/inputwin.c
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c35
-rw-r--r--src/common.c14
-rw-r--r--src/log.c8
-rw-r--r--src/ui/console.c10
4 files changed, 42 insertions, 25 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 6eca1bd1..3c1a0980 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1046,12 +1046,13 @@ _who_roster(gchar **args, struct cmd_help_t help)
     } else if (strcmp("available", presence) == 0) {
         GSList *filtered = NULL;
 
-        while (list != NULL) {
-            PContact contact = list->data;
+        GSList *curr = list;
+        while (curr != NULL) {
+            PContact contact = curr->data;
             if (p_contact_is_available(contact)) {
                 filtered = g_slist_append(filtered, contact);
             }
-            list = g_slist_next(list);
+            curr = g_slist_next(curr);
         }
 
         if (group != NULL) {
@@ -1075,12 +1076,13 @@ _who_roster(gchar **args, struct cmd_help_t help)
     } else if (strcmp("unavailable", presence) == 0) {
         GSList *filtered = NULL;
 
-        while (list != NULL) {
-            PContact contact = list->data;
+        GSList *curr = list;
+        while (curr != NULL) {
+            PContact contact = curr->data;
             if (!p_contact_is_available(contact)) {
                 filtered = g_slist_append(filtered, contact);
             }
-            list = g_slist_next(list);
+            curr = g_slist_next(curr);
         }
 
         if (group != NULL) {
@@ -1104,12 +1106,13 @@ _who_roster(gchar **args, struct cmd_help_t help)
     } else if (strcmp("online", presence) == 0) {
         GSList *filtered = NULL;
 
-        while (list != NULL) {
-            PContact contact = list->data;
+        GSList *curr = list;
+        while (curr != NULL) {
+            PContact contact = curr->data;
             if (p_contact_has_available_resource(contact)) {
                 filtered = g_slist_append(filtered, contact);
             }
-            list = g_slist_next(list);
+            curr = g_slist_next(curr);
         }
 
         if (group != NULL) {
@@ -1133,12 +1136,13 @@ _who_roster(gchar **args, struct cmd_help_t help)
     } else if (strcmp("offline", presence) == 0) {
         GSList *filtered = NULL;
 
-        while (list != NULL) {
-            PContact contact = list->data;
+        GSList *curr = list;
+        while (curr != NULL) {
+            PContact contact = curr->data;
             if (!p_contact_has_available_resource(contact)) {
                 filtered = g_slist_append(filtered, contact);
             }
-            list = g_slist_next(list);
+            curr = g_slist_next(curr);
         }
 
         if (group != NULL) {
@@ -1162,12 +1166,13 @@ _who_roster(gchar **args, struct cmd_help_t help)
     } else {
         GSList *filtered = NULL;
 
-        while (list != NULL) {
-            PContact contact = list->data;
+        GSList *curr = list;
+        while (curr != NULL) {
+            PContact contact = curr->data;
             if (strcmp(p_contact_presence(contact), presence) == 0) {
                 filtered = g_slist_append(filtered, contact);
             }
-            list = g_slist_next(list);
+            curr = g_slist_next(curr);
         }
 
         if (group != NULL) {
diff --git a/src/common.c b/src/common.c
index 0c10a568..7a9848ff 100644
--- a/src/common.c
+++ b/src/common.c
@@ -500,25 +500,34 @@ cmp_win_num(gconstpointer a, gconstpointer b)
 int
 get_next_available_win_num(GList *used)
 {
-    used = g_list_sort(used, cmp_win_num);
     // only console used
     if (g_list_length(used) == 1) {
         return 2;
     } else {
+        GList *sorted = NULL;
+        GList *curr = used;
+        while (curr) {
+            sorted = g_list_insert_sorted(sorted, curr->data, cmp_win_num);
+            curr = g_list_next(curr);
+        }
+
         int result = 0;
         int last_num = 1;
-        GList *curr = used;
+        curr = sorted;
         // skip console
         curr = g_list_next(curr);
         while (curr != NULL) {
             int curr_num = GPOINTER_TO_INT(curr->data);
+
             if (((last_num != 9) && ((last_num + 1) != curr_num)) ||
                     ((last_num == 9) && (curr_num != 0))) {
                 result = last_num + 1;
                 if (result == 10) {
                     result = 0;
                 }
+                g_list_free(sorted);
                 return (result);
+
             } else {
                 last_num = curr_num;
                 if (last_num == 0) {
@@ -532,6 +541,7 @@ get_next_available_win_num(GList *used)
             result = 0;
         }
 
+        g_list_free(sorted);
         return result;
     }
 }
diff --git a/src/log.c b/src/log.c
index c525c3d9..4270a54f 100644
--- a/src/log.c
+++ b/src/log.c
@@ -236,7 +236,7 @@ chat_log_init(void)
 {
     session_started = g_date_time_new_now_local();
     log_info("Initialising chat logs");
-    logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free,
+    logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, free,
         (GDestroyNotify)_free_chat_log);
 }
 
@@ -244,7 +244,7 @@ void
 groupchat_log_init(void)
 {
     log_info("Initialising groupchat logs");
-    groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free,
+    groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, free,
         (GDestroyNotify)_free_chat_log);
 }
 
@@ -396,8 +396,8 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient)
 void
 chat_log_close(void)
 {
-    g_hash_table_remove_all(logs);
-    g_hash_table_remove_all(groupchat_logs);
+    g_hash_table_destroy(logs);
+    g_hash_table_destroy(groupchat_logs);
     g_date_time_unref(session_started);
 }
 
diff --git a/src/ui/console.c b/src/ui/console.c
index 14ee7314..57af809e 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -251,6 +251,7 @@ cons_show_wins(void)
         win_save_println(console, curr->data);
         curr = g_slist_next(curr);
     }
+    g_slist_free_full(window_strings, free);
 
     cons_show("");
     cons_alert();
@@ -402,17 +403,18 @@ cons_show_sent_subs(void)
         GSList *contacts = roster_get_contacts();
         PContact contact = NULL;
         cons_show("Awaiting subscription responses from:");
-        while (contacts != NULL) {
-            contact = (PContact) contacts->data;
+        GSList *curr = contacts;
+        while (curr != NULL) {
+            contact = (PContact) curr->data;
             if (p_contact_pending_out(contact)) {
                 cons_show("  %s", p_contact_barejid(contact));
             }
-            contacts = g_slist_next(contacts);
+            curr = g_slist_next(curr);
         }
+        g_slist_free(contacts);
     } else {
         cons_show("No pending requests sent.");
     }
-
     cons_alert();
 }