# HG changeset patch # User Mark Doliner # Date 1226742245 0 # Node ID ae66b7b3086a5ff6b36b9e39a0b1c65a116b3eac # Parent a58d730c85f6e45e4362cab45b635e61d624a01f 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. diff -r a58d730c85f6 -r ae66b7b3086a libpurple/protocols/msn/httpconn.c --- a/libpurple/protocols/msn/httpconn.c Sat Nov 15 07:43:48 2008 +0000 +++ b/libpurple/protocols/msn/httpconn.c Sat Nov 15 09:44:05 2008 +0000 @@ -119,7 +119,7 @@ /* 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 @@ 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 @@ 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 @@ 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 @@ { /* 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; } diff -r a58d730c85f6 -r ae66b7b3086a libpurple/protocols/msn/servconn.c --- a/libpurple/protocols/msn/servconn.c Sat Nov 15 07:43:48 2008 +0000 +++ b/libpurple/protocols/msn/servconn.c Sat Nov 15 09:44:05 2008 +0000 @@ -375,15 +375,14 @@ 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);