From ab5eadc559df2fd8ce2ec00abaca2f40fff05cff Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Sep 2013 14:47:17 +0100 Subject: [PATCH 01/11] Fix nickname change conflicts fixes #242 --- src/profanity.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/profanity.c b/src/profanity.c index bcb59395..48f8a3f5 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -198,7 +198,9 @@ prof_handle_error_message(const char *from, const char *err_msg) } // remove the room from muc Jid *room_jid = jid_create(from); - muc_leave_room(room_jid->barejid); + if (!muc_get_roster_received(room_jid->barejid)) { + muc_leave_room(room_jid->barejid); + } jid_destroy(room_jid); } else { From 426b669c35eddb96964e4c45eaa75944d63cb75a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Sep 2013 22:43:13 +0100 Subject: [PATCH 02/11] Added configure-debug script --- configure-debug | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 configure-debug diff --git a/configure-debug b/configure-debug new file mode 100755 index 00000000..9819cfeb --- /dev/null +++ b/configure-debug @@ -0,0 +1,3 @@ +#!/bin/sh + +./configure CFLAGS='-g -O0' CXXFLAGS='-g -O0' From 927af868c7381d3a0012436d1acb41a22d6bbb94 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Sep 2013 23:11:28 +0100 Subject: [PATCH 03/11] Use stack rather than heap for autcomplete_param_with_func issue #226 --- src/tools/autocomplete.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 77d8c7ae..438b48b7 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -176,7 +176,7 @@ autocomplete_param_with_func(char *input, int *size, char *command, char *auto_msg = NULL; char inp_cpy[*size]; int i; - char *command_cpy = malloc(strlen(command) + 2); + char command_cpy[strlen(command) + 2]; sprintf(command_cpy, "%s ", command); int len = strlen(command_cpy); if ((strncmp(input, command_cpy, len) == 0) && (*size > len)) { @@ -192,7 +192,6 @@ autocomplete_param_with_func(char *input, int *size, char *command, free(found); } } - free(command_cpy); return auto_msg; } From e3e1341c9a1d175251975447c05d0872e644ecc3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Sep 2013 23:16:54 +0100 Subject: [PATCH 04/11] Fixed memory leak in accounts_get_account issue #226 --- src/config/accounts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/accounts.c b/src/config/accounts.c index b903d6be..7b9c6a6c 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -259,7 +259,7 @@ accounts_get_account(const char * const name) account->muc_nick = strdup(jidp->localpart); jid_destroy(jidp); } else { - account->muc_nick = strdup(muc_nick); + account->muc_nick = muc_nick; } // get room history From 9ea85475fe2d7d4e34ef11c45772ef2da33db49c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Sep 2013 23:24:54 +0100 Subject: [PATCH 05/11] Fixed memory leak in _cmd_connect issue #226 --- src/command/command.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command/command.c b/src/command/command.c index 711f94e9..9ece5964 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1368,6 +1368,7 @@ _cmd_connect(gchar **args, struct cmd_help_t help) cons_show("Connecting as %s", jid); conn_status = jabber_connect_with_details(jid, passwd, altdomain); } + g_free(lower); if (conn_status == JABBER_DISCONNECTED) { cons_show_error("Connection attempt for %s failed.", jid); From e7159aca3030085f0bc6263fbf8586b56c1a512b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Sep 2013 23:30:00 +0100 Subject: [PATCH 06/11] Fixed memory leak in accounts_get_account issue #226 --- src/config/accounts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/accounts.c b/src/config/accounts.c index 7b9c6a6c..4eb4b8e3 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -250,7 +250,7 @@ accounts_get_account(const char * const name) g_string_free(g_muc_service, TRUE); jid_destroy(jidp); } else { - account->muc_service = strdup(muc_service); + account->muc_service = muc_service; } gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL); From cb507497b63c4a7f16792d76f28af967099ceb41 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Sep 2013 23:39:56 +0100 Subject: [PATCH 07/11] Fixed memory leak in parse_args_with_freetext issue #226 --- src/tools/parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/parser.c b/src/tools/parser.c index f273923a..942b17ca 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -256,6 +256,8 @@ parse_args_with_freetext(const char * const inp, int min, int max) } } + free(copy); + if (in_token) { tokens = g_slist_append(tokens, g_strndup(token_start, token_size)); } @@ -265,7 +267,6 @@ parse_args_with_freetext(const char * const inp, int min, int max) // if num args not valid return NULL if ((num < min) || (num > max)) { g_slist_free_full(tokens, free); - free(copy); return NULL; // if min allowed is 0 and 0 found, return empty char* array @@ -288,7 +289,6 @@ parse_args_with_freetext(const char * const inp, int min, int max) args[arg_count] = NULL; g_slist_free_full(tokens, free); - free(copy); return args; } From 25b274b8d1b322121edcfa4bf4cff6f03b9c820e Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Sep 2013 01:05:07 +0100 Subject: [PATCH 08/11] Fixed memory leaks in chat logs issue #226 --- src/log.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/log.c b/src/log.c index 14d801a9..5a278872 100644 --- a/src/log.c +++ b/src/log.c @@ -214,18 +214,17 @@ void chat_log_chat(const gchar * const login, gchar *other, const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) { - gchar *other_copy = strdup(other); - struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other_copy); + struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other); // no log for user if (dated_log == NULL) { - dated_log = _create_log(other_copy, login); - g_hash_table_insert(logs, other_copy, dated_log); + dated_log = _create_log(other, login); + g_hash_table_insert(logs, strdup(other), dated_log); // log exists but needs rolling } else if (_log_roll_needed(dated_log)) { - dated_log = _create_log(other_copy, login); - g_hash_table_replace(logs, other_copy, dated_log); + dated_log = _create_log(other, login); + g_hash_table_replace(logs, strdup(other), dated_log); } gchar *date_fmt = NULL; @@ -242,9 +241,9 @@ chat_log_chat(const gchar * const login, gchar *other, if (direction == PROF_IN_LOG) { if (strncmp(msg, "/me ", 4) == 0) { - fprintf(logp, "%s - *%s %s\n", date_fmt, other_copy, msg + 4); + fprintf(logp, "%s - *%s %s\n", date_fmt, other, msg + 4); } else { - fprintf(logp, "%s - %s: %s\n", date_fmt, other_copy, msg); + fprintf(logp, "%s - %s: %s\n", date_fmt, other, msg); } } else { if (strncmp(msg, "/me ", 4) == 0) { @@ -413,8 +412,8 @@ _free_chat_log(struct dated_chat_log *dated_log) g_date_time_unref(dated_log->date); dated_log->date = NULL; } + free(dated_log); } - dated_log = NULL; } static @@ -450,6 +449,7 @@ _get_log_filename(const char * const other, const char * const login, gchar *date = g_date_time_format(dt, "/%Y_%m_%d.log"); g_string_append(log_file, date); + g_free(date); char *result = strdup(log_file->str); g_string_free(log_file, TRUE); From b738e8f363e3470eb97ac941d945194e19f3c198 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Sep 2013 01:19:54 +0100 Subject: [PATCH 09/11] Moved free in parse_args_with_freetext issue #226 --- src/tools/parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/parser.c b/src/tools/parser.c index 942b17ca..1ec539df 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -256,12 +256,12 @@ parse_args_with_freetext(const char * const inp, int min, int max) } } - free(copy); - if (in_token) { tokens = g_slist_append(tokens, g_strndup(token_start, token_size)); } + free(copy); + int num = g_slist_length(tokens) - 1; // if num args not valid return NULL From 70452c119453f491be537aec214ae76449d8ace8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Sep 2013 01:34:35 +0100 Subject: [PATCH 10/11] Fixed memory leak in _cmd_join issue #226 --- src/command/command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 9ece5964..e8232405 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -2725,6 +2725,7 @@ static gboolean _cmd_join(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); + ProfAccount *account = accounts_get_account(jabber_get_account_name()); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); @@ -2749,7 +2750,6 @@ _cmd_join(gchar **args, struct cmd_help_t help) // server not supplied (room), use account preference } else { - ProfAccount *account = accounts_get_account(jabber_get_account_name()); g_string_append(room_str, args[0]); g_string_append(room_str, "@"); g_string_append(room_str, account->muc_service); @@ -2762,7 +2762,6 @@ _cmd_join(gchar **args, struct cmd_help_t help) // otherwise use account preference } else { - ProfAccount *account = accounts_get_account(jabber_get_account_name()); nick = account->muc_nick; } @@ -2778,6 +2777,7 @@ _cmd_join(gchar **args, struct cmd_help_t help) jid_destroy(room_jid); jid_destroy(my_jid); g_string_free(room_str, TRUE); + accounts_free_account(account); return TRUE; } From ce3b99f5771809f38119e9449099bdb1b0768b8f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Sep 2013 01:37:57 +0100 Subject: [PATCH 11/11] Fixed memory leak in groupchat logging issue #226 --- src/log.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/log.c b/src/log.c index 5a278872..4442dcfd 100644 --- a/src/log.c +++ b/src/log.c @@ -486,6 +486,7 @@ _get_groupchat_log_filename(const char * const room, const char * const login, gchar *date = g_date_time_format(dt, "/%Y_%m_%d.log"); g_string_append(log_file, date); + g_free(date); char *result = strdup(log_file->str); g_string_free(log_file, TRUE);