changeset 22832:f62a4a7fe365

Fix a number of leaks. As far as I can tell, MSNP14 now logs in without leaking.
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 03 May 2008 23:51:43 +0000
parents 0b11895cc564
children 7492fdcdbcea
files libpurple/protocols/msn/contact.c libpurple/protocols/msn/dialog.c libpurple/protocols/msn/nexus.c libpurple/protocols/msn/notification.c libpurple/protocols/msn/oim.c libpurple/protocols/msn/page.c libpurple/protocols/msn/slpcall.c libpurple/protocols/msn/slplink.c libpurple/protocols/msn/slpmsg.c libpurple/protocols/msn/soap2.c libpurple/protocols/msn/sync.c libpurple/protocols/msn/userlist.c
diffstat 12 files changed, 52 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/contact.c	Sat May 03 23:51:43 2008 +0000
@@ -100,56 +100,46 @@
 void
 msn_callback_state_set_who(MsnCallbackState *state, const gchar *who)
 {
-	gchar *nval;
 	g_return_if_fail(state != NULL);
 
-	nval = g_strdup(who);
 	g_free(state->who);
-	state->who = nval;
+	state->who = g_strdup(who);
 }
 
 void
 msn_callback_state_set_uid(MsnCallbackState *state, const gchar *uid)
 {
-	gchar *nval;
 	g_return_if_fail(state != NULL);
 
-	nval = g_strdup(uid);
 	g_free(state->uid);
-	state->uid = nval;
+	state->uid = g_strdup(uid);
 }
 
 void
 msn_callback_state_set_old_group_name(MsnCallbackState *state, const gchar *old_group_name)
 {
-	gchar *nval;
 	g_return_if_fail(state != NULL);
 
-	nval = g_strdup(old_group_name);
 	g_free(state->old_group_name);
-	state->old_group_name = nval;
+	state->old_group_name = g_strdup(old_group_name);
 }
 
 void
 msn_callback_state_set_new_group_name(MsnCallbackState *state, const gchar *new_group_name)
 {
-	gchar *nval;
 	g_return_if_fail(state != NULL);
 
-	nval = g_strdup(new_group_name);
 	g_free(state->new_group_name);
-	state->new_group_name = nval;
+	state->new_group_name = g_strdup(new_group_name);
 }
 
 void
 msn_callback_state_set_guid(MsnCallbackState *state, const gchar *guid)
 {
-	gchar *nval;
 	g_return_if_fail(state != NULL);
 
-	nval = g_strdup(guid);
 	g_free(state->guid);
-	state->guid = nval;
+	state->guid = g_strdup(guid);
 }
 
 
@@ -539,6 +529,7 @@
 		g_free(Name);
 		g_free(uid);
 		g_free(type);
+		g_free(mobile_number);
 		passport = Name = uid = type = mobile_number = NULL;
 		mobile = FALSE;
 
@@ -660,6 +651,7 @@
 	g_free(Name);
 	g_free(uid);
 	g_free(type);
+	g_free(mobile_number);
 }
 
 static gboolean
--- a/libpurple/protocols/msn/dialog.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/dialog.c	Sat May 03 23:51:43 2008 +0000
@@ -112,7 +112,7 @@
 
 	data        = g_new0(MsnAddRemData, 1);
 	data->who   = g_strdup(passport);
-	data->group = group_name != NULL ? g_strdup(group_name) : NULL;
+	data->group = g_strdup(group_name);
 	data->gc    = gc;
 
 	msg = g_strdup_printf(_("Buddy list synchronization issue in %s (%s)"),
--- a/libpurple/protocols/msn/nexus.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/nexus.c	Sat May 03 23:51:43 2008 +0000
@@ -52,6 +52,7 @@
 	if (nexus->challenge_data != NULL)
 		g_hash_table_destroy(nexus->challenge_data);
 
+	g_free(nexus->challenge_data_str);
 	g_free(nexus);
 }
 
@@ -101,13 +102,10 @@
 			msn_twn_p = g_hash_table_lookup(nexus->challenge_data, "p");
 
 			/*setup the t and p parameter for session*/
-			if (session->passport_info.t != NULL){
-				g_free(session->passport_info.t);
-			}
+			g_free(session->passport_info.t);
 			session->passport_info.t = g_strdup(msn_twn_t);
 
-			if (session->passport_info.p != NULL)
-				g_free(session->passport_info.p);
+			g_free(session->passport_info.p);
 			session->passport_info.p = g_strdup(msn_twn_p);
 
 			cert_str = g_strdup_printf("t=%s&p=%s",msn_twn_t,msn_twn_p);
@@ -133,7 +131,8 @@
 	MsnSession *session = nexus->session;
 	char *ru,*lc,*id,*tw,*ct,*kpp,*kv,*ver,*rn,*tpf;
 	char *fs0,*fs;
-	char *username, *password;
+	const char *username;
+	char *password;
 	char *tail;
 #ifdef NEXUS_LOGIN_TWN
 	char *challenge_str;
@@ -147,7 +146,7 @@
 	msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE);
 
 	/*prepare the Windows Live ID authentication token*/
-	username = g_strdup(purple_account_get_username(session->account));
+	username = purple_account_get_username(session->account);
 	password = g_strndup(purple_connection_get_password(session->account->gc), 16);
 
 	lc =	(char *)g_hash_table_lookup(nexus->challenge_data, "lc");
@@ -170,7 +169,6 @@
 	if(!(lc && id && tw && ru && ct && kpp && kv && ver && tpf)){
 		purple_debug_error("MSN Nexus","WLM Authenticate Key Error!\n");
 		msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication Failed"));
-		g_free(username);
 		g_free(password);
 		msn_nexus_destroy(nexus);
 		session->nexus = NULL;
--- a/libpurple/protocols/msn/notification.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/notification.c	Sat May 03 23:51:43 2008 +0000
@@ -414,7 +414,9 @@
 	{
 		g_return_if_fail(cmd->payload_cb != NULL);
 
-		purple_debug_info("MSNP14", "MSG payload:{%.*s}\n", (guint)(cmd->payload_len), cmd->payload);
+#if 0 /* glib on win32 doesn't correctly support precision modifiers for a string */
+		purple_debug_info("MSNP14", "MSG payload:{%.*s}\n", cmd->payload_len, cmd->payload);
+#endif
 		cmd->payload_cb(cmdproc, cmd, cmd->payload, cmd->payload_len);
 	}
 }
@@ -647,8 +649,8 @@
 {
 	MsnTransaction *trans;
 	purple_debug_info("MSN Notification","Sending ADL with payload: %s\n", payload);
-	trans = msn_transaction_new(cmdproc, "ADL","%" G_GSIZE_FORMAT, strlen(payload));
-	msn_transaction_set_payload(trans, payload, strlen(payload));
+	trans = msn_transaction_new(cmdproc, "ADL","%" G_GSIZE_FORMAT, payload_len);
+	msn_transaction_set_payload(trans, payload, payload_len);
 	msn_cmdproc_send_trans(cmdproc, trans);
 }
 
@@ -1705,6 +1707,9 @@
 		msn_user_set_currentmedia(user, &media);
 	else
 		msn_user_set_currentmedia(user, NULL);
+	g_free(media.title);
+	g_free(media.album);
+	g_free(media.artist);
 	g_free(str);
 
 	msn_user_update(user);
--- a/libpurple/protocols/msn/oim.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/oim.c	Sat May 03 23:51:43 2008 +0000
@@ -58,7 +58,7 @@
 
 	oim = g_new0(MsnOim, 1);
 	oim->session = session;
-	oim->oim_list	= NULL;
+	oim->oim_list = NULL;
 	oim->run_id = rand_guid();
 	oim->challenge = NULL;
 	oim->send_queue = g_queue_new();
@@ -71,16 +71,18 @@
 msn_oim_destroy(MsnOim *oim)
 {
 	MsnOimSendReq *request;
-	
-	purple_debug_info("OIM","destroy the OIM \n");
+
+	purple_debug_info("OIM", "destroy the OIM %p\n", oim);
 	g_free(oim->run_id);
 	g_free(oim->challenge);
-	
+
 	while((request = g_queue_pop_head(oim->send_queue)) != NULL){
 		msn_oim_free_send_req(request);
 	}
+
 	g_queue_free(oim->send_queue);
-	
+	g_list_free(oim->oim_list);
+
 	g_free(oim);
 }
 
@@ -91,7 +93,7 @@
 	MsnOimSendReq *request;
 	
 	request = g_new0(MsnOimSendReq, 1);
-	request->from_member	=g_strdup(from_member);
+	request->from_member	= g_strdup(from_member);
 	request->friendname		= g_strdup(friendname);
 	request->to_member		= g_strdup(to_member);
 	request->oim_msg		= g_strdup(msg);
@@ -472,7 +474,7 @@
 	xmlnode *iu_node;
 	MsnSession *session = oim->session;
 
-	purple_debug_info("MSNP14:OIM", "%s", xmlmsg);
+	purple_debug_info("MSNP14:OIM", "%s\n", xmlmsg);
 
 	node = xmlnode_from_str(xmlmsg, -1);
 	if (strcmp(node->name, "MD") != 0) {
--- a/libpurple/protocols/msn/page.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/page.c	Sat May 03 23:51:43 2008 +0000
@@ -39,14 +39,9 @@
 {
 	g_return_if_fail(page != NULL);
 
-	if (page->body != NULL)
-		g_free(page->body);
-
-	if (page->from_location != NULL)
-		g_free(page->from_location);
-
-	if (page->from_phone != NULL)
-		g_free(page->from_phone);
+	g_free(page->body);
+	g_free(page->from_location);
+	g_free(page->from_phone);
 
 	g_free(page);
 }
--- a/libpurple/protocols/msn/slpcall.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/slpcall.c	Sat May 03 23:51:43 2008 +0000
@@ -71,14 +71,9 @@
 	if (slpcall->timer)
 		purple_timeout_remove(slpcall->timer);
 
-	if (slpcall->id != NULL)
-		g_free(slpcall->id);
-
-	if (slpcall->branch != NULL)
-		g_free(slpcall->branch);
-
-	if (slpcall->data_info != NULL)
-		g_free(slpcall->data_info);
+	g_free(slpcall->id);
+	g_free(slpcall->branch);
+	g_free(slpcall->data_info);
 
 	for (e = slpcall->slplink->slp_msgs; e != NULL; )
 	{
--- a/libpurple/protocols/msn/slplink.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/slplink.c	Sat May 03 23:51:43 2008 +0000
@@ -101,11 +101,8 @@
 
 	session = slplink->session;
 
-	if (slplink->local_user != NULL)
-		g_free(slplink->local_user);
-
-	if (slplink->remote_user != NULL)
-		g_free(slplink->remote_user);
+	g_free(slplink->local_user);
+	g_free(slplink->remote_user);
 
 #if 0
 	if (slplink->directconn != NULL)
--- a/libpurple/protocols/msn/slpmsg.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/slpmsg.c	Sat May 03 23:51:43 2008 +0000
@@ -95,6 +95,7 @@
 		msg->nak_cb = NULL;
 		msg->ack_data = NULL;
 	}
+	g_list_free(slpmsg->msgs);
 
 	slplink->slp_msgs = g_list_remove(slplink->slp_msgs, slpmsg);
 
--- a/libpurple/protocols/msn/soap2.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/soap2.c	Sat May 03 23:51:43 2008 +0000
@@ -261,7 +261,7 @@
 static void
 msn_soap_read_cb(gpointer data, gint fd, PurpleInputCondition cond)
 {
-    MsnSoapConnection *conn = data;
+	MsnSoapConnection *conn = data;
 	int count = 0, cnt;
 	char buf[8192];
 	char *linebreak;
@@ -382,7 +382,7 @@
 	}
 
 	if (!handled && conn->headers_done) {
-		if (conn->buf->len - conn->handled_len >= 
+		if (conn->buf->len - conn->handled_len >=
 			conn->body_len) {
 			xmlnode *node = xmlnode_from_str(cursor, conn->body_len);
 
@@ -394,8 +394,11 @@
 				conn->message = NULL;
 				message->xml = node;
 
-				if (!msn_soap_handle_body(conn, message))
+				if (!msn_soap_handle_body(conn, message)) {
+					msn_soap_message_destroy(message);
 					return;
+				}
+				msn_soap_message_destroy(message);
 			}
 
 			msn_soap_connection_handle_next(conn);
@@ -508,7 +511,7 @@
 
 			g_free(authstr);
 			g_free(body);
-		}		
+		}
 	}
 
 	return FALSE;
@@ -643,12 +646,12 @@
 }
 
 void
-msn_soap_message_add_header(MsnSoapMessage *req,
+msn_soap_message_add_header(MsnSoapMessage *message,
 		const char *name, const char *value)
 {
 	char *header = g_strdup_printf("%s: %s\r\n", name, value);
 
-	req->headers = g_slist_prepend(req->headers, header);
+	message->headers = g_slist_prepend(message->headers, header);
 }
 
 static void
--- a/libpurple/protocols/msn/sync.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/sync.c	Sat May 03 23:51:43 2008 +0000
@@ -156,16 +156,13 @@
 
 		for (c = tokens; *c != NULL; c++)
 		{
-			char *id;
-
-			id = *c;
-			group_ids = g_slist_append(group_ids, g_strdup(id));
+			group_ids = g_slist_append(group_ids, *c);
 		}
 
-		g_strfreev(tokens);
 
 		msn_got_lst_user(session, user, list_op, group_ids);
 
+		g_strfreev(tokens);
 		g_slist_free(group_ids);
 	}
 	else
--- a/libpurple/protocols/msn/userlist.c	Sat May 03 21:03:13 2008 +0000
+++ b/libpurple/protocols/msn/userlist.c	Sat May 03 23:51:43 2008 +0000
@@ -349,8 +349,7 @@
 		GSList *c;
 		for (c = group_ids; c != NULL; c = g_slist_next(c))
 		{
-			char *group_id;
-			group_id = c->data;
+			char *group_id = c->data;
 			msn_user_add_group_id(user, group_id);
 		}