# HG changeset patch # User Stu Tomlinson # Date 1101868247 0 # Node ID f776e117c17bb8b0901806a27fdfa08af9a92428 # Parent 60d2e2bad26b59929f661523b58ac3cf606fa930 [gaim-migrate @ 11454] Several MSN memory leaks identified and fixed by Miah Gregory and Felipe Contreras, plus my own fix for bug 1075347. As normal, thank them for fixes, blame me for breakages. Did I mention the new MSN icon? It rocks! committer: Tailor Script diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/cmdproc.c --- a/src/protocols/msn/cmdproc.c Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/cmdproc.c Wed Dec 01 02:30:47 2004 +0000 @@ -116,6 +116,9 @@ data = msn_transaction_to_string(trans); + if (cmdproc->last_trans != NULL) + g_free(cmdproc->last_trans); + cmdproc->last_trans = g_strdup(data); len = strlen(data); diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/msg.c --- a/src/protocols/msn/msg.c Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/msg.c Wed Dec 01 02:30:47 2004 +0000 @@ -121,11 +121,13 @@ g_return_if_fail(payload != NULL); - tmp_base = tmp = g_memdup(payload, payload_len + 1); - tmp[payload_len] = '\0'; + tmp_base = tmp = g_memdup(payload, payload_len); /* Parse the attributes. */ end = strstr(tmp, "\r\n\r\n"); + /* TODO? some clients use \r delimiters instead of \r\n, the official client + * doesn't send such messages, but does handle receiving them. We'll just + * avoid crashing for now */ g_return_if_fail(end != NULL); *end = '\0'; @@ -141,7 +143,10 @@ value = tokens[1]; if (!strcmp(key, "MIME-Version")) + { + g_strfreev(tokens); continue; + } if (!strcmp(key, "Content-Type")) { @@ -214,7 +219,7 @@ else { msg->body_len = payload_len - (tmp - tmp_base); - msg->body = g_memdup(tmp, msg->body_len + 1); + msg->body = g_memdup(tmp, msg->body_len); } g_free(tmp_base); @@ -582,18 +587,21 @@ msn_message_get_hashtable_from_body(const MsnMessage *msg) { GHashTable *table; + size_t body_len; const char *body; - char **elems, **cur, **tokens; + char **elems, **cur, **tokens, *body_str; g_return_val_if_fail(msg != NULL, NULL); table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - body = msn_message_get_bin_data(msg, NULL); + body = msn_message_get_bin_data(msg, &body_len); g_return_val_if_fail(body != NULL, NULL); - elems = g_strsplit(body, "\r\n", 0); + body_str = g_strndup(body, body_len); + elems = g_strsplit(body_str, "\r\n", 0); + g_free(body_str); for (cur = elems; *cur != NULL; cur++) { diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/notification.c --- a/src/protocols/msn/notification.c Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/notification.c Wed Dec 01 02:30:47 2004 +0000 @@ -235,7 +235,6 @@ msn_message_parse_payload(msg, payload, len); /* msn_message_show_readable(msg, "Notification", TRUE); */ - msg->remote_user = g_strdup(cmd->params[0]); msn_cmdproc_process_msg(cmdproc, msg); msn_message_destroy(msg); @@ -947,16 +946,36 @@ return; if ((value = msn_message_get_attr(msg, "kv")) != NULL) + { + if (session->passport_info.kv != NULL) + g_free(session->passport_info.kv); + session->passport_info.kv = g_strdup(value); + } if ((value = msn_message_get_attr(msg, "sid")) != NULL) + { + if (session->passport_info.sid != NULL) + g_free(session->passport_info.sid); + session->passport_info.sid = g_strdup(value); + } if ((value = msn_message_get_attr(msg, "MSPAuth")) != NULL) + { + if (session->passport_info.mspauth != NULL) + g_free(session->passport_info.mspauth); + session->passport_info.mspauth = g_strdup(value); + } if ((value = msn_message_get_attr(msg, "ClientIP")) != NULL) + { + if (session->passport_info.client_ip != NULL) + g_free(session->passport_info.client_ip); + session->passport_info.client_ip = g_strdup(value); + } if ((value = msn_message_get_attr(msg, "ClientPort")) != NULL) session->passport_info.client_port = ntohs(atoi(value)); @@ -1158,8 +1177,9 @@ if (cmdproc->error) return; - session->user = msn_user_new(session->userlist, - gaim_account_get_username(account), NULL); + if (session->user == NULL) + session->user = msn_user_new(session->userlist, + gaim_account_get_username(account), NULL); #if 0 gaim_connection_update_progress(gc, _("Syncing with server"), diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/session.c --- a/src/protocols/msn/session.c Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/session.c Wed Dec 01 02:30:47 2004 +0000 @@ -87,6 +87,9 @@ if (session->passport_info.mspauth != NULL) g_free(session->passport_info.mspauth); + if (session->passport_info.client_ip != NULL) + g_free(session->passport_info.client_ip); + if (session->passport_info.file != NULL) { unlink(session->passport_info.file); diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/slplink.c --- a/src/protocols/msn/slplink.c Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/slplink.c Wed Dec 01 02:30:47 2004 +0000 @@ -351,6 +351,8 @@ msg->ack_data = slpmsg; msn_slplink_send_msgpart(slplink, slpmsg); + + msn_message_destroy(msg); } void diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/slpmsg.c --- a/src/protocols/msn/slpmsg.c Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/slpmsg.c Wed Dec 01 02:30:47 2004 +0000 @@ -65,10 +65,20 @@ if (slpmsg->msg != NULL) { - if (slpmsg->msg->trans != NULL) + MsnTransaction *trans; + + trans = slpmsg->msg->trans; + + if (trans != NULL) { - slpmsg->msg->trans->callbacks = NULL; - slpmsg->msg->trans->data = NULL; + /* Something is pointing to this slpmsg, so we should remove that + * pointer to prevent a crash. */ + + if (trans->callbacks != NULL && trans->has_custom_callbacks) + g_hash_table_destroy(trans->callbacks); + + trans->callbacks = NULL; + trans->data = NULL; } } diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/switchboard.c --- a/src/protocols/msn/switchboard.c Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/switchboard.c Wed Dec 01 02:30:47 2004 +0000 @@ -280,6 +280,9 @@ msn_message_parse_payload(msg, payload, len); /* msn_message_show_readable(msg, "SB RECV", FALSE); */ + if (msg->remote_user != NULL) + g_free (msg->remote_user); + msg->remote_user = g_strdup(cmd->params[0]); msn_cmdproc_process_msg(cmdproc, msg); @@ -526,7 +529,9 @@ msg = cmd->trans->data; - msg->ack_cb (msg->ack_data); + msg->ack_cb(msg->ack_data); + + msn_message_unref(msg); } void @@ -551,6 +556,7 @@ /* Data for callbacks */ msn_transaction_set_data(trans, msg); + msn_message_ref(msg); if (msg->ack_cb != NULL) { diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/transaction.c --- a/src/protocols/msn/transaction.c Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/transaction.c Wed Dec 01 02:30:47 2004 +0000 @@ -75,6 +75,9 @@ } #endif + if (trans->callbacks != NULL && trans->has_custom_callbacks) + g_hash_table_destroy(trans->callbacks); + if (trans->timer) gaim_timeout_remove(trans->timer); @@ -167,7 +170,13 @@ g_return_if_fail(answer != NULL); if (trans->callbacks == NULL) - trans->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); + { + trans->has_custom_callbacks = TRUE; + trans->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + NULL); + } + else if (trans->has_custom_callbacks != TRUE) + g_return_if_reached (); g_hash_table_insert(trans->callbacks, answer, cb); } diff -r 60d2e2bad26b -r f776e117c17b src/protocols/msn/transaction.h --- a/src/protocols/msn/transaction.h Wed Dec 01 01:17:46 2004 +0000 +++ b/src/protocols/msn/transaction.h Wed Dec 01 02:30:47 2004 +0000 @@ -49,6 +49,7 @@ void *data; /* The data to be used on the different callbacks */ GHashTable *callbacks; + gboolean has_custom_callbacks; MsnErrorCb error_cb; MsnTimeoutCb timeout_cb;