pidgin: 3ae49ca1: Make the two "read_cb()" functions more ...

markdoliner at pidgin.im markdoliner at pidgin.im
Sat Nov 15 04:45:33 EST 2008


-----------------------------------------------------------------
Revision: 3ae49ca1a268aa770e70e984052bb869bcb28f39
Ancestor: e438832e5bd5ff654f547a5628889c5047640928
Author: markdoliner at pidgin.im
Date: 2008-11-15T09:44:05
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/3ae49ca1a268aa770e70e984052bb869bcb28f39

Modified files:
        libpurple/protocols/msn/httpconn.c
        libpurple/protocols/msn/servconn.c

ChangeLog: 

Make the two "read_cb()" functions more similar, and fix a rare
memleak in httpconn by adding a call to g_free(header).  Only
happens if the server sends us abnormal data.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/httpconn.c	0544210f4c50b355e675bf2885e1b83e913f9cdb
+++ libpurple/protocols/msn/httpconn.c	8ffcbf5c8c6a3e93428f66e85738c27e9cb2f460
@@ -119,7 +119,7 @@ msn_httpconn_parse_data(MsnHttpConn *htt
 		/* Need to wait for the full HTTP header to arrive */
 		return FALSE;
 
-	s += 4; /* Skip \r\n */
+	s += 4; /* Skip \r\n\r\n */
 	header = g_strndup(buf, s - buf);
 	body_start = s;
 	body_len = size - (body_start - buf);
@@ -162,7 +162,7 @@ msn_httpconn_parse_data(MsnHttpConn *htt
 	body[body_len] = '\0';
 
 #ifdef MSN_DEBUG_HTTP
-	purple_debug_misc("msn", "Incoming HTTP buffer (header): {%s\r\n}\n",
+	purple_debug_misc("msn", "Incoming HTTP buffer (header): {%s}\n",
 					header);
 #endif
 
@@ -184,6 +184,7 @@ msn_httpconn_parse_data(MsnHttpConn *htt
 			purple_debug_error("msn", "Malformed X-MSN-Messenger field.\n{%s}\n",
 							 buf);
 
+			g_free(header);
 			g_free(body);
 			return FALSE;
 		}
@@ -278,17 +279,20 @@ read_cb(gpointer data, gint source, Purp
 	gboolean error = FALSE;
 
 	httpconn = data;
-	servconn = NULL;
+	servconn = httpconn->servconn;
 	session = httpconn->session;
 
+	if (servconn->type == MSN_SERVCONN_NS)
+		session->account->gc->last_received = time(NULL);
+
 	len = read(httpconn->fd, buf, sizeof(buf) - 1);
-
 	if (len < 0 && errno == EAGAIN)
 		return;
-	else if (len <= 0)
-	{
-		purple_debug_error("msn", "HTTP: Read error\n");
-		msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
+	if (len <= 0) {
+		purple_debug_error("msn", "HTTP: servconn %03d read error, "
+			"len: %" G_GSSIZE_FORMAT ", errno: %d, error: %s\n",
+			servconn->num, len, error, g_strerror(errno));
+		msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ);
 
 		return;
 	}
@@ -304,17 +308,15 @@ read_cb(gpointer data, gint source, Purp
 	{
 		/* Either we must wait for more input, or something went wrong */
 		if (error)
-			msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
+			msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ);
 
 		return;
 	}
 
-	servconn = httpconn->servconn;
-
 	if (error)
 	{
 		purple_debug_error("msn", "HTTP: Special error\n");
-		msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
+		msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ);
 
 		return;
 	}
============================================================
--- libpurple/protocols/msn/servconn.c	59f5a37f6d599d753b380898f5fd0a9825506837
+++ libpurple/protocols/msn/servconn.c	cede462f3948ed80de75053518092bdad5ba9376
@@ -375,15 +375,14 @@ read_cb(gpointer data, gint source, Purp
 	servconn = data;
 	session = servconn->session;
 
-	len = read(servconn->fd, buf, sizeof(buf) - 1);
 	if (servconn->type == MSN_SERVCONN_NS)
-		servconn->session->account->gc->last_received = time(NULL);
+		session->account->gc->last_received = time(NULL);
 
-	if (len < 0 && errno == EAGAIN) {
+	len = read(servconn->fd, buf, sizeof(buf) - 1);
+	if (len < 0 && errno == EAGAIN)
 		return;
-
-	} else if (len <= 0) {
-		purple_debug_error("msn", "servconn %03d read error,"
+	if (len <= 0) {
+		purple_debug_error("msn", "servconn %03d read error, "
 			"len: %" G_GSSIZE_FORMAT ", errno: %d, error: %s\n",
 			servconn->num, len, errno, g_strerror(errno));
 		msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ);


More information about the Commits mailing list