pidgin: f8d85e2f: Fix a number of leaks. As far as I can ...

datallah at pidgin.im datallah at pidgin.im
Sat May 3 19:56:40 EDT 2008


-----------------------------------------------------------------
Revision: f8d85e2fccdd5166da0ce2d35db65d64a19d0256
Ancestor: 2aab3939318b7e131386caf77cf2641f6b0b3e0f
Author: datallah at pidgin.im
Date: 2008-05-03T23:51:43
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f8d85e2fccdd5166da0ce2d35db65d64a19d0256

Modified 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

ChangeLog: 

Fix a number of leaks.  As far as I can tell, MSNP14 now logs in without
leaking.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/contact.c	afe1017912a48bc32607d7a5f3666da2c73dd06d
+++ libpurple/protocols/msn/contact.c	71c0671cc3483499fc8351745f1b336449bbb619
@@ -100,56 +100,46 @@ msn_callback_state_set_who(MsnCallbackSt
 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 @@ msn_parse_addressbook_contacts(MsnContac
 		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 @@ msn_parse_addressbook_contacts(MsnContac
 	g_free(Name);
 	g_free(uid);
 	g_free(type);
+	g_free(mobile_number);
 }
 
 static gboolean
============================================================
--- libpurple/protocols/msn/dialog.c	85136580a20d10914756e9156e086d7b1087eaf4
+++ libpurple/protocols/msn/dialog.c	6ed6f93494bc7d48915a543a6e1ee12b7f556bb6
@@ -112,7 +112,7 @@ msn_show_sync_issue(MsnSession *session,
 
 	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)"),
============================================================
--- libpurple/protocols/msn/nexus.c	2a84e972ed3df60af3b4a0f0106b750c1f1ee56f
+++ libpurple/protocols/msn/nexus.c	75b3377621ffb38d7431853070c9a9d71eff66b6
@@ -52,6 +52,7 @@ msn_nexus_destroy(MsnNexus *nexus)
 	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 @@ nexus_got_response_cb(MsnSoapMessage *re
 			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 @@ msn_nexus_connect(MsnNexus *nexus)
 	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_nexus_connect(MsnNexus *nexus)
 	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 @@ msn_nexus_connect(MsnNexus *nexus)
 	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;
============================================================
--- libpurple/protocols/msn/notification.c	4024481f241bd238d95124f90f00fa8251e8d85a
+++ libpurple/protocols/msn/notification.c	ae639f781fd769a918d5c0836414432446853fe1
@@ -414,7 +414,9 @@ msg_cmd(MsnCmdProc *cmdproc, MsnCommand 
 	{
 		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 @@ msn_notification_post_adl(MsnCmdProc *cm
 {
 	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 @@ ubx_cmd_post(MsnCmdProc *cmdproc, MsnCom
 		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);
============================================================
--- libpurple/protocols/msn/oim.c	47f44889144bdbcd8abbff53b650d6d07861992a
+++ libpurple/protocols/msn/oim.c	d68c3d59668fc477e443521ad8c1004b8f165651
@@ -58,7 +58,7 @@ msn_oim_new(MsnSession *session)
 
 	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)
 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 @@ msn_oim_new_send_req(const char *from_me
 	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 @@ msn_parse_oim_msg(MsnOim *oim,const char
 	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) {
============================================================
--- libpurple/protocols/msn/page.c	cc244355a3c715228e6c8974481591a55960ec81
+++ libpurple/protocols/msn/page.c	6adc9b1d22cd6d87f024b4188eb5c62410c5d162
@@ -39,15 +39,10 @@ msn_page_destroy(MsnPage *page)
 {
 	g_return_if_fail(page != NULL);
 
-	if (page->body != NULL)
-		g_free(page->body);
+	g_free(page->body);
+	g_free(page->from_location);
+	g_free(page->from_phone);
 
-	if (page->from_location != NULL)
-		g_free(page->from_location);
-
-	if (page->from_phone != NULL)
-		g_free(page->from_phone);
-
 	g_free(page);
 }
 
============================================================
--- libpurple/protocols/msn/slpcall.c	6fe8eaabbb668caf72ebf2f75cd8701a5ed38fcf
+++ libpurple/protocols/msn/slpcall.c	8950866bafc860ef44dab541d02f43a66a781474
@@ -71,15 +71,10 @@ msn_slp_call_destroy(MsnSlpCall *slpcall
 	if (slpcall->timer)
 		purple_timeout_remove(slpcall->timer);
 
-	if (slpcall->id != NULL)
-		g_free(slpcall->id);
+	g_free(slpcall->id);
+	g_free(slpcall->branch);
+	g_free(slpcall->data_info);
 
-	if (slpcall->branch != NULL)
-		g_free(slpcall->branch);
-
-	if (slpcall->data_info != NULL)
-		g_free(slpcall->data_info);
-
 	for (e = slpcall->slplink->slp_msgs; e != NULL; )
 	{
 		MsnSlpMessage *slpmsg = e->data;
============================================================
--- libpurple/protocols/msn/slplink.c	e227291ffa8aaf340455f2408c4a24271da3612f
+++ libpurple/protocols/msn/slplink.c	3b445961c805b0f26d74fcb25cc0b60b944d8f18
@@ -101,12 +101,9 @@ msn_slplink_destroy(MsnSlpLink *slplink)
 
 	session = slplink->session;
 
-	if (slplink->local_user != NULL)
-		g_free(slplink->local_user);
+	g_free(slplink->local_user);
+	g_free(slplink->remote_user);
 
-	if (slplink->remote_user != NULL)
-		g_free(slplink->remote_user);
-
 #if 0
 	if (slplink->directconn != NULL)
 		msn_directconn_destroy(slplink->directconn);
============================================================
--- libpurple/protocols/msn/slpmsg.c	2bb5642de9d0eba1cbc2938063a2b85d49faff30
+++ libpurple/protocols/msn/slpmsg.c	ce95fd395b071e62edff3c220a9cc5bcd53920bf
@@ -95,6 +95,7 @@ msn_slpmsg_destroy(MsnSlpMessage *slpmsg
 		msg->nak_cb = NULL;
 		msg->ack_data = NULL;
 	}
+	g_list_free(slpmsg->msgs);
 
 	slplink->slp_msgs = g_list_remove(slplink->slp_msgs, slpmsg);
 
============================================================
--- libpurple/protocols/msn/soap2.c	361b8c0970e8a5a128dc56c0d557857e69737ce0
+++ libpurple/protocols/msn/soap2.c	4f776f5dd94626b4cdeb5fb050cc3c52f41ef473
@@ -261,7 +261,7 @@ msn_soap_read_cb(gpointer data, gint fd,
 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 @@ msn_soap_read_cb(gpointer data, gint fd,
 	}
 
 	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 @@ msn_soap_read_cb(gpointer data, gint fd,
 				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 @@ msn_soap_connection_run(gpointer data)
 
 			g_free(authstr);
 			g_free(body);
-		}		
+		}
 	}
 
 	return FALSE;
@@ -643,12 +646,12 @@ void
 }
 
 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
============================================================
--- libpurple/protocols/msn/sync.c	85a72d9061e53e69ee27083a796bdb08e5cec907
+++ libpurple/protocols/msn/sync.c	e5d8fb58240c16ec7efce53e0e444a09d4e5291a
@@ -156,16 +156,13 @@ lst_cmd(MsnCmdProc *cmdproc, MsnCommand 
 
 		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
============================================================
--- libpurple/protocols/msn/userlist.c	d9266dc3b23115952608fcda8d7d17b565209816
+++ libpurple/protocols/msn/userlist.c	874479ab987591b6c18545e645e49d0f460d3df0
@@ -349,8 +349,7 @@ msn_got_lst_user(MsnSession *session, Ms
 		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);
 		}
 


More information about the Commits mailing list