changeset 11439:617e67e1c985

[gaim-migrate @ 13676] Fixed a couple leaks and potential leaks. The retval of g_strsplit() needs to be g_strfreev()'d. Also some "declaration after code" fixes. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 04 Sep 2005 18:05:48 +0000
parents 5451fe2d89c0
children 5938f6b386fa
files src/protocols/simple/simple.c src/protocols/simple/sipmsg.c
diffstat 2 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/simple/simple.c	Sun Sep 04 07:14:04 2005 +0000
+++ b/src/protocols/simple/simple.c	Sun Sep 04 18:05:48 2005 +0000
@@ -297,6 +297,7 @@
 	int i=0;
 	char *tmp;
 	char *tmp2;
+	gchar **parts;
 	if(!hdr) {
 		gaim_debug_error("simple", "fill_auth: hdr==NULL\n");
 		return;
@@ -306,7 +307,7 @@
 		gaim_debug_info("simple", "found NTLM\n");
 		auth->type = 2;
 		if(!auth->nonce && !auth->nc) {
-			gchar **parts = g_strsplit(hdr, " ", 0);
+			parts = g_strsplit(hdr, " ", 0);
 			while(parts[i]) {
 				if(!strncmp(parts[i],"targetname",10)) {
 					auth->target = g_strndup(parts[i]+12,strlen(parts[i]+12)-1);
@@ -321,6 +322,8 @@
 				}
 				i++;
 			}
+			g_strfreev(parts);
+			parts = NULL;
 			auth->nc = 1;
 		}
 		if(!auth->nonce && auth->nc==2) {
@@ -331,7 +334,7 @@
 	}
 
 	auth->type = 1;
-	gchar **parts = g_strsplit(hdr, " ", 0);
+	parts = g_strsplit(hdr, " ", 0);
 	while(parts[i]) {
 		if(!strncmp(parts[i],"nonce",5)) {
 			auth->nonce = g_strndup(parts[i]+7,strlen(parts[i]+7)-1);
@@ -341,6 +344,7 @@
 		}
 		i++;
 	}
+	g_strfreev(parts);
 
 	gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s ", auth->nonce, auth->realm);
 
@@ -554,12 +558,12 @@
 }
 
 static void do_register_exp(struct simple_account_data *sip, int expire) {
-	sip->registerstatus = 1;
-
 	char *uri = g_strdup_printf("sip:%s",sip->servername);
 	char *to = g_strdup_printf("sip:%s@%s",sip->username,sip->servername);
 	char *contact = g_strdup_printf("Contact: <sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"\r\nExpires: %d\r\n", sip->username, sip->ip ? sip->ip : "", sip->listenport, sip->udp ? "udp" : "tcp", expire);
 
+	sip->registerstatus = 1;
+
 	if(expire) {
 		sip->reregister = time(NULL) + expire - 50;
 	} else {
@@ -988,13 +992,13 @@
 		struct transaction *trans = transactions_find(sip, msg);
 		if(trans) {
 			if(msg->response == 407) {
+				gchar *resend, *auth, *ptmp;
+
 				if(sip->proxy.retries>3) return;
 				sip->proxy.retries++;
 				/* do proxy authentication */
 
-				gchar *ptmp = sipmsg_find_header(msg,"Proxy-Authenticate");
-				gchar *resend;
-				gchar *auth;
+				ptmp = sipmsg_find_header(msg, "Proxy-Authenticate");
 
 				fill_auth(sip, ptmp, &sip->proxy);
 				auth = auth_header(sip, &sip->proxy, trans->msg->method, trans->msg->target);
--- a/src/protocols/simple/sipmsg.c	Sun Sep 04 07:14:04 2005 +0000
+++ b/src/protocols/simple/sipmsg.c	Sun Sep 04 18:05:48 2005 +0000
@@ -56,6 +56,8 @@
 	int i=1;
 	parts = g_strsplit(lines[0], " ", 3);
 	if(!parts[0] || !parts[1] || !parts[2]) {
+		g_strfreev(parts);
+		g_strfreev(lines);
 		g_free(msg);
 		return NULL;
 	}
@@ -71,6 +73,8 @@
 	for(i=1; lines[i] && strlen(lines[i])>2; i++) {
 		parts = g_strsplit(lines[i], ":", 2);
 		if(!parts[0] || !parts[1]) {
+			g_strfreev(parts);
+			g_strfreev(lines);
 			g_free(msg);
 			return NULL;
 		}
@@ -89,6 +93,7 @@
 		sipmsg_add_header(msg, parts[0], dummy2);
 		g_strfreev(parts);
 	}
+	g_strfreev(lines);
 	msg->bodylen = strtol(sipmsg_find_header(msg, "Content-Length"),NULL,10);
 	if(msg->response) {
 		tmp = sipmsg_find_header(msg, "CSeq");
@@ -113,11 +118,11 @@
 	cur = msg->headers;
 	while(cur) {
 		elem = cur->data;
-	        gaim_debug(GAIM_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value);
+		gaim_debug(GAIM_DEBUG_MISC, "simple", "name: %s value: %s\n",elem->name, elem->value);
 		cur = g_slist_next(cur);
 	}
 }
-	
+
 char *sipmsg_to_string(struct sipmsg *msg) {
 	gchar *out;
 	gchar *old;
@@ -129,7 +134,7 @@
 	while(cur) {
 		elem = cur->data;
 		old = out;
-	        out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value);
+		out = g_strdup_printf("%s%s: %s\r\n", out, elem->name, elem->value);
 		g_free(old);
 		cur = g_slist_next(cur);
 	}
@@ -150,7 +155,7 @@
 	element->value = g_strdup(value);
 	msg->headers = g_slist_append(msg->headers, element);
 }
-			
+
 void sipmsg_free(struct sipmsg *msg) {
 	struct siphdrelement *elem;
 	while(msg->headers) {