From 6bee6cb0fbc7215091cbcbe9d146835a1a5405cb Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 19:30:18 +0000 Subject: [PATCH 1/6] Free string on backspace --- src/ui/inputwin.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index b2d5e420..269d6fa7 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -611,17 +611,17 @@ _handle_backspace(void) } else if (inp_x > 0 && inp_x < display_size) { gchar *start = g_utf8_substring(input, 0, inp_x - 1); gchar *end = g_utf8_substring(input, inp_x, input_len_bytes); - GString *new = g_string_new(start); - g_string_append(new, end); + GString *new_str = g_string_new(start); + g_string_append(new_str, end); - for (input_len_bytes = 0; input_len_bytes < strlen(new->str); input_len_bytes++) { - input[input_len_bytes] = new->str[input_len_bytes]; + for (input_len_bytes = 0; input_len_bytes < strlen(new_str->str); input_len_bytes++) { + input[input_len_bytes] = new_str->str[input_len_bytes]; } input[input_len_bytes] = '\0'; g_free(start); g_free(end); - g_string_free(new, FALSE); + g_string_free(new_str, TRUE); _clear_input(); waddstr(inp_win, input); From 30739ed157efcacd38dee69e35872f8ca9215b2f Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 19:39:18 +0000 Subject: [PATCH 2/6] Free contact list --- src/command/commands.c | 1 + src/ui/console.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 6eca1bd1..af5c8cc8 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1188,6 +1188,7 @@ _who_roster(gchar **args, struct cmd_help_t help) g_slist_free(filtered); } + list = g_slist_nth(list, 0); g_slist_free(list); } diff --git a/src/ui/console.c b/src/ui/console.c index 2c37c40c..8d6f88b4 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -402,17 +402,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(); } From 75d766387677c783694df9ccfda9dffbb3bf4ef7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 19:42:13 +0000 Subject: [PATCH 3/6] Free wins summary list --- src/ui/console.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/console.c b/src/ui/console.c index 8d6f88b4..c1bfe450 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(); From 22b92c751445b14e35b9b0e94479f79d2434c0a5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 19:53:34 +0000 Subject: [PATCH 4/6] Used g_hash_table_destroy to free logs --- src/log.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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); } From e565812d09cc3b257792cbafbb7ee1aa37d238c3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 20:30:50 +0000 Subject: [PATCH 5/6] Free roster list --- src/command/commands.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index af5c8cc8..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) { @@ -1188,7 +1193,6 @@ _who_roster(gchar **args, struct cmd_help_t help) g_slist_free(filtered); } - list = g_slist_nth(list, 0); g_slist_free(list); } From 6ab937c3e37b71315ab8661c6188ded49dfa182b Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 20:39:57 +0000 Subject: [PATCH 6/6] Copy list when sorting windows for /wins --- src/common.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/common.c b/src/common.c index 95deecbb..3af4f550 100644 --- a/src/common.c +++ b/src/common.c @@ -488,25 +488,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) { @@ -520,6 +529,7 @@ get_next_available_win_num(GList *used) result = 0; } + g_list_free(sorted); return result; } }