Mercurial > pidgin
changeset 20989:2097b1664fa3
Fix some leaks and prevent some unnecessary allocations and frees.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Thu, 18 Oct 2007 23:51:10 +0000 |
parents | 9375e1a9a196 |
children | bc731b26335c |
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 |
diffstat | 6 files changed, 29 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/msn/msg.c Thu Oct 18 21:00:06 2007 +0000 +++ b/libpurple/protocols/msn/msg.c Thu Oct 18 23:51:10 2007 +0000 @@ -313,6 +313,7 @@ /* 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 @@ { 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); }
--- a/libpurple/protocols/msn/msn.c Thu Oct 18 21:00:06 2007 +0000 +++ b/libpurple/protocols/msn/msn.c Thu Oct 18 23:51:10 2007 +0000 @@ -254,6 +254,7 @@ 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 @@ 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;
--- a/libpurple/protocols/msn/nexus.c Thu Oct 18 21:00:06 2007 +0000 +++ b/libpurple/protocols/msn/nexus.c Thu Oct 18 23:51:10 2007 +0000 @@ -228,7 +228,7 @@ 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 @@ 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)); - - request_str = g_strdup_printf("%s%s", head,tail); + "Cache-Control: no-cache\r\n\r\n" + "%s", + soapconn->login_path, soapconn->login_host, strlen(tail), + 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);
--- a/libpurple/protocols/msn/notification.c Thu Oct 18 21:00:06 2007 +0000 +++ b/libpurple/protocols/msn/notification.c Thu Oct 18 23:51:10 2007 +0000 @@ -465,15 +465,12 @@ 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 @@ } 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){
--- a/libpurple/protocols/msn/oim.c Thu Oct 18 21:00:06 2007 +0000 +++ b/libpurple/protocols/msn/oim.c Thu Oct 18 23:51:10 2007 +0000 @@ -40,7 +40,7 @@ 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 @@ * 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 @@ 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 @@ 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,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_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,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_get_read_cb, msn_oim_get_written_cb, msn_oim_retrieve_connect_init); + g_free(soap_body); msn_soap_post(oim->retrieveconn,soap_request); }
--- a/libpurple/protocols/msn/soap.c Thu Oct 18 21:00:06 2007 +0000 +++ b/libpurple/protocols/msn/soap.c Thu Oct 18 23:51:10 2007 +0000 @@ -679,6 +679,8 @@ 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 @@ 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 @@ #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 @@ "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 @@ 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*/