im.pidgin.pidgin: 2907a074c5a977fcfe123292bbde28f0b16296f7

datallah at pidgin.im datallah at pidgin.im
Thu Oct 18 19:55:40 EDT 2007


-----------------------------------------------------------------
Revision: 2907a074c5a977fcfe123292bbde28f0b16296f7
Ancestor: fe00ca8a057e772d955ff56c7b6557e221d3e514
Author: datallah at pidgin.im
Date: 2007-10-18T23:51:10
Branch: im.pidgin.pidgin

Modified files:
        libpurple/protocols/msn/msg.c libpurple/protocols/msn/msn.c
        libpurple/protocols/msn/nexus.c
        libpurple/protocols/msn/notification.c
        libpurple/protocols/msn/oim.c libpurple/protocols/msn/soap.c

ChangeLog: 

Fix some leaks and prevent some unnecessary allocations and frees.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msg.c	be278ff1429ee99bf96b26105834592f1a166367
+++ libpurple/protocols/msn/msg.c	550615fd5684bc982bf640bc153a63c104082213
@@ -313,6 +313,7 @@ msn_message_parse_payload(MsnMessage *ms
 		/* Import the body. */
 		if (body_len > 0) {
 			msg->body_len = body_len;
+			g_free(msg->body);
 			msg->body = g_malloc0(msg->body_len + 1);
 			memcpy(msg->body, tmp, msg->body_len);
 			tmp += body_len;
@@ -329,6 +330,7 @@ msn_message_parse_payload(MsnMessage *ms
 	{
 		if (payload_len - (tmp - tmp_base) > 0) {
 			msg->body_len = payload_len - (tmp - tmp_base);
+			g_free(msg->body);
 			msg->body = g_malloc0(msg->body_len + 1);
 			memcpy(msg->body, tmp, msg->body_len);
 		}
============================================================
--- libpurple/protocols/msn/msn.c	7438ee0f6da09fa24c50aedff8c603bc0bd08ddf
+++ libpurple/protocols/msn/msn.c	b07df2bd8dd167a626174dba019f64ed3fed755c
@@ -254,6 +254,7 @@ send_to_mobile(PurpleConnection *gc, con
 	trans = msn_transaction_new(cmdproc, "PGD", "%s 1 %d", who, payload_len);
 
 	msn_transaction_set_payload(trans, payload, payload_len);
+	g_free(payload);
 
 	msn_page_destroy(page);
 
@@ -1982,7 +1983,7 @@ msn_got_info(PurpleUtilFetchUrlData *url
 	purple_debug_info("MSNP14","photo url:{%s}\n", photo_url_text ? photo_url_text : "(null)");
 
 	/* Marshall the existing state */
-	info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData));
+	info2_data = g_new0(MsnGetInfoStepTwoData, 1);
 	info2_data->info_data = info_data;
 	info2_data->stripped = stripped;
 	info2_data->url_buffer = url_buffer;
============================================================
--- libpurple/protocols/msn/nexus.c	9bd63395fda2ec18e2fcbcfed61c1376c3d22903
+++ libpurple/protocols/msn/nexus.c	4a2d80e504e329b1ee2a6970825380c97c22b262
@@ -228,7 +228,7 @@ nexus_login_connect_cb(MsnSoapConn *soap
 	char *ru,*lc,*id,*tw,*ct,*kpp,*kv,*ver,*rn,*tpf;
 	char *fs0,*fs;
 	char *username, *password;
-	char *request_str, *head, *tail;
+	char *request_str, *tail;
 #ifdef NEXUS_LOGIN_TWN
 	char *challenge_str;
 #else
@@ -318,22 +318,21 @@ nexus_login_connect_cb(MsnSoapConn *soap
 	g_free(fs);
 
 	soapconn->login_path = g_strdup(TWN_POST_URL);
-	head = g_strdup_printf(
+	request_str = g_strdup_printf(
 					"POST %s HTTP/1.1\r\n"
 					"Accept: text/*\r\n"
 					"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
 					"Host: %s\r\n"
 					"Content-Length: %" G_GSIZE_FORMAT "\r\n"
 					"Connection: Keep-Alive\r\n"
-					"Cache-Control: no-cache\r\n\r\n",
-					soapconn->login_path, soapconn->login_host, strlen(tail));
+					"Cache-Control: no-cache\r\n\r\n"
+					"%s",
+					soapconn->login_path, soapconn->login_host, strlen(tail),
+					tail);
 
-	request_str = g_strdup_printf("%s%s", head,tail);
-
 #ifdef MSN_SOAP_DEBUG	
 	purple_debug_misc("MSN Nexus", "TWN Sending:\n%s\n", request_str);
 #endif
-	g_free(head);
 	g_free(tail);
 	g_free(username);
 	g_free(password);
============================================================
--- libpurple/protocols/msn/notification.c	36ab027d085d41a0aa02373b32d1860e508eb898
+++ libpurple/protocols/msn/notification.c	f36c96e9af4b7fbaa8aa6da40cdb06a558af93e5
@@ -465,15 +465,12 @@ ubm_cmd_post(MsnCmdProc *cmdproc, MsnCom
 	if(!strcmp(content_type,"text/plain")){
 		const char *value;
 		const char *body;
-		char *body_str;
 		char *body_enc;
 		char *body_final = NULL;
 		size_t body_len;
 
 		body = msn_message_get_bin_data(msg, &body_len);
-		body_str = g_strndup(body, body_len);
-		body_enc = g_markup_escape_text(body_str, -1);
-		g_free(body_str);
+		body_enc = g_markup_escape_text(body, body_len);
 
 		if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL)	{
 			char *pre, *post;
@@ -486,6 +483,7 @@ ubm_cmd_post(MsnCmdProc *cmdproc, MsnCom
 		}
 		g_free(body_enc);
 		serv_got_im(gc, passport, body_final, 0, time(NULL));
+		g_free(body_final);
 	}
 	if(!strcmp(content_type,"text/x-msmsgscontrol")){
 		if(msn_message_get_attr(msg, "TypingUser") != NULL){
============================================================
--- libpurple/protocols/msn/oim.c	7413546d1cd5e152f445c306b1dbfffb6f6b8858
+++ libpurple/protocols/msn/oim.c	6792ae4e207d35a5ea31e12c36ec431397a115a7
@@ -40,7 +40,7 @@ static void msn_oim_get_process(MsnOim *
 static void msn_oim_free_send_req(MsnOimSendReq *req);
 static void msn_oim_report_to_user(MsnOim *oim, const char *msg_str);
 static void msn_oim_get_process(MsnOim *oim, const char *oim_msg);
-static char *msn_oim_msg_to_str(MsnOim *oim, const char *body);
+static gchar *msn_oim_msg_to_str(MsnOim *oim, const char *body);
 static void msn_oim_send_process(MsnOim *oim, const char *body, int len);
 
 /*new a OIM object*/
@@ -115,7 +115,7 @@ msn_oim_free_send_req(MsnOimSendReq *req
  * OIM send SOAP request
  * **************************************/
 /*encode the message to OIM Message Format*/
-static char *
+static gchar *
 msn_oim_msg_to_str(MsnOim *oim, const char *body)
 {
 	char *oim_body,*oim_base64;
@@ -125,6 +125,7 @@ msn_oim_msg_to_str(MsnOim *oim, const ch
 	purple_debug_info("MSN OIM","encoded base64 body:{%s}\n",oim_base64);	
 	oim_body = g_strdup_printf(MSN_OIM_MSG_TEMPLATE,
 				oim->run_id,oim->send_seq,oim_base64);
+	g_free(oim_base64);
 
 	return oim_body;
 }
@@ -280,7 +281,7 @@ msn_oim_send_msg(MsnOim *oim)
 	MsnSoapReq *soap_request;
 	MsnOimSendReq *oim_request;
 	char *soap_body,*mspauth;
-	char *msg_body;
+	gchar *msg_body;
 	char buf[33];
 
 	g_return_if_fail(oim != NULL);
@@ -362,7 +363,8 @@ msn_oim_post_delete_msg(MsnOim *oim,cons
 msn_oim_post_delete_msg(MsnOim *oim,const char *msgid)
 {
 	MsnSoapReq *soap_request;
-	const char *soap_body,*t,*p;
+	gchar *soap_body;
+	const char *t,*p;
 
 	g_return_if_fail(oim != NULL);
 	g_return_if_fail(msgid != NULL);
@@ -384,6 +386,7 @@ msn_oim_post_delete_msg(MsnOim *oim,cons
 					msn_oim_delete_read_cb,
 					msn_oim_delete_written_cb,
 					msn_oim_retrieve_connect_init);
+	g_free(soap_body);
 	msn_soap_post(oim->retrieveconn,soap_request);
 }
 
@@ -669,7 +672,8 @@ msn_oim_post_single_get_msg(MsnOim *oim,
 msn_oim_post_single_get_msg(MsnOim *oim,const char *msgid)
 {
 	MsnSoapReq *soap_request;
-	const char *soap_body,*t,*p;
+	gchar *soap_body;
+	const char *t,*p;
 
 	purple_debug_info("MSN OIM","Get single OIM Message\n");
 	t = oim->session->passport_info.t;
@@ -688,6 +692,7 @@ msn_oim_post_single_get_msg(MsnOim *oim,
 					msn_oim_get_read_cb,
 					msn_oim_get_written_cb,
 					msn_oim_retrieve_connect_init);
+	g_free(soap_body);
 	msn_soap_post(oim->retrieveconn,soap_request);
 }
 
============================================================
--- libpurple/protocols/msn/soap.c	33b40542abf405a280d4b032f13aee7b01fc8cb7
+++ libpurple/protocols/msn/soap.c	92d4ba1fc4f25a60c17f698d362128e8b8c28ae6
@@ -679,6 +679,8 @@ msn_soap_write(MsnSoapConn * soapconn, c
 
 	msn_soap_set_process_step(soapconn, MSN_SOAP_PROCESSING);
 
+	/* Ideally this wouldn't ever be necessary, but i believe that it is leaking the previous value */
+	g_free(soapconn->write_buf);
 	soapconn->write_buf = write_buf;
 	soapconn->written_len = 0;
 	soapconn->written_cb = written_cb;
@@ -822,7 +824,6 @@ msn_soap_post_request(MsnSoapConn *soapc
 void
 msn_soap_post_request(MsnSoapConn *soapconn, MsnSoapReq *request)
 {
-	char * soap_head = NULL;
 	char * request_str = NULL;
 #ifdef MSN_SOAP_DEBUG
 #if !defined(_WIN32)
@@ -832,7 +833,7 @@ msn_soap_post_request(MsnSoapConn *soapc
 #endif
 
 	msn_soap_set_process_step(soapconn, MSN_SOAP_PROCESSING);
-	soap_head = g_strdup_printf(
+	request_str = g_strdup_printf(
 					"POST %s HTTP/1.1\r\n"
 					"SOAPAction: %s\r\n"
 					"Content-Type:text/xml; charset=utf-8\r\n"
@@ -842,14 +843,15 @@ msn_soap_post_request(MsnSoapConn *soapc
 					"Host: %s\r\n"
 					"Content-Length: %" G_GSIZE_FORMAT "\r\n"
 					"Connection: Keep-Alive\r\n"
-					"Cache-Control: no-cache\r\n\r\n",
+					"Cache-Control: no-cache\r\n\r\n"
+					"%s",
 					request->login_path,
 					request->soap_action,
 					soapconn->session->passport_info.mspauth,
 					request->login_host,
-					strlen(request->body)
+					strlen(request->body),
+					request->body
 					);
-	request_str = g_strdup_printf("%s%s", soap_head, request->body);
 
 #if defined(MSN_SOAP_DEBUG) && !defined(_WIN32)
 	node = xmlnode_from_str(request->body, -1);
@@ -863,7 +865,6 @@ msn_soap_post_request(MsnSoapConn *soapc
 		purple_debug_info("MSN SOAP","Failed to parse SOAP request being sent:\n%s\n", request_str);
 #endif
 	
-	g_free(soap_head);
 	/*free read buffer*/
 	// msn_soap_free_read_buf(soapconn);
 	/*post it to server*/


More information about the Commits mailing list