----------------------------------------------------------------- Revision: afa2cfc77d5df43359af0e531c44167cf94d7d06 Ancestor: efedefa70ee1d6f7f4dd39afe5db10c7e5bfe64c Author: markdoliner@pidgin.im Date: 2007-09-26T07:25:22 Branch: im.pidgin.pidgin Modified files: libpurple/protocols/myspace/markup.c libpurple/protocols/myspace/message.c libpurple/protocols/myspace/myspace.c ChangeLog: Fix lots of little memory leaks in the MySpace protocol plugin. GString's need to be free'd, and the string passed to g_string_new() is duplicated when inserted into the GString, so it still needs to be free'd. ============================================================ --- libpurple/protocols/myspace/markup.c 58f21b7150ffc5540638233b0a52304c43adac9f +++ libpurple/protocols/myspace/markup.c 3281e6e2711eecf12224b5cad5dbc8fea7de161e @@ -258,8 +258,8 @@ msim_markup_f_to_html(MsimSession *sessi } - *begin = gs_begin->str; - *end = gs_end->str; + *begin = g_string_free(gs_begin, FALSE); + *end = g_string_free(gs_end, FALSE); } /** Convert a msim markup color to a color suitable for libpurple. @@ -596,7 +596,7 @@ msim_convert_xmlnode(MsimSession *sessio purple_debug_info("msim", "msim_markup_xmlnode_to_gtkhtml: RETURNING %s\n", (final && final->str) ? final->str : "(NULL)"); - return final->str; + return g_string_free(final, FALSE); } /** Convert XML to something based on MSIM_XMLNODE_CONVERT. */ ============================================================ --- libpurple/protocols/myspace/message.c 19e5e096ed9a522b98d3740c62fa62b5cab9cab5 +++ libpurple/protocols/myspace/message.c 19818f7c026c6e17696b19ad8af7087633baa252 @@ -80,7 +80,7 @@ msim_escape(const gchar *msg) purple_debug_info("msim", "msim_escape: msg=%s, ret=%s\n", msg, gs->str); #endif - return gs->str; + return g_string_free(gs, FALSE); } /** @@ -120,7 +120,7 @@ msim_unescape(const gchar *msg) purple_debug_info("msim", "msim_unescape: msg=%s, ret=%s\n", msg, gs->str); #endif - return gs->str; + return g_string_free(gs, FALSE); } /** Create a new MsimMessage. @@ -691,7 +691,7 @@ msim_msg_debug_string_element(gpointer d ++i; } - string = gs->str; + string = g_string_free(gs, FALSE); break; default: @@ -798,7 +798,7 @@ msim_msg_pack_element_data(MsimMessageEl g_string_append(gs, "|"); } - return gs->str; + return g_string_free(gs, FALSE); default: purple_debug_info("msim", "field %s, unknown type %d\n", @@ -1337,9 +1337,7 @@ msim_msg_get_binary_from_element(MsimMes gs = (GString *)elem->data; /* Duplicate data, so caller can g_free() it. */ - *binary_data = g_new0(char, gs->len); - memcpy(*binary_data, gs->str, gs->len); - + *binary_data = g_memdup(gs->str, gs->len); *binary_length = gs->len; return TRUE; ============================================================ --- libpurple/protocols/myspace/myspace.c df6c9c801b7c8d98075dcd4a83b9631f025ff0b9 +++ libpurple/protocols/myspace/myspace.c 743ade3ce41bbeea939e4cce6ffee011f9b17e4a @@ -43,7 +43,7 @@ static gboolean msim_login_challenge(Msi static int msim_send_really_raw(PurpleConnection *gc, const char *buf, int total_bytes); static gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg); -static const gchar *msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], const gchar *email, const gchar *password, guint *response_len); +static gchar *msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], const gchar *email, const gchar *password, guint *response_len); static gboolean msim_incoming_bm_record_cv(MsimSession *session, MsimMessage *msg); static gboolean msim_incoming_bm(MsimSession *session, MsimMessage *msg); @@ -332,10 +332,11 @@ msim_login_challenge(MsimSession *sessio msim_login_challenge(MsimSession *session, MsimMessage *msg) { PurpleAccount *account; - const gchar *response; + gchar *response; guint response_len; gchar *nc; gsize nc_len; + gboolean ret; g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); g_return_val_if_fail(msg != NULL, FALSE); @@ -363,11 +364,11 @@ msim_login_challenge(MsimSession *sessio g_free(nc); - return msim_send(session, + ret = msim_send(session, "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM, /* This is actually user's email address. */ "username", MSIM_TYPE_STRING, g_strdup(account->username), - /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */ + /* GString will be freed in msim_msg_free() in msim_send(). */ "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len), "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION, "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH, @@ -376,6 +377,10 @@ msim_login_challenge(MsimSession *sessio "status", MSIM_TYPE_INTEGER, 100, "id", MSIM_TYPE_INTEGER, 1, NULL); + + g_free(response); + + return ret; } /** @@ -389,7 +394,7 @@ msim_login_challenge(MsimSession *sessio * @return Binary login challenge response, ready to send to the server. * Must be g_free()'d when finished. NULL if error. */ -static const gchar * +static gchar * msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], const gchar *email, const gchar *password, guint *response_len) { @@ -488,6 +493,7 @@ msim_compute_login_response(const gchar data_len, data_out, &data_out_len); purple_cipher_context_destroy(rc4); + /* TODO: Never assert in a protocol plugin! */ g_assert(data_out_len == data_len); #ifdef MSIM_DEBUG_LOGIN_CHALLENGE @@ -496,7 +502,7 @@ msim_compute_login_response(const gchar *response_len = data_out_len; - return (const gchar *)data_out; + return (gchar *)data_out; } /** @@ -1297,7 +1303,6 @@ msim_check_inbox_cb(MsimSession *session msim_check_inbox_cb(MsimSession *session, MsimMessage *reply, gpointer data) { MsimMessage *body; - GString *notification; guint old_inbox_status; guint i, n; const gchar *froms[5], *tos[5], *urls[5], *subjects[5]; @@ -1331,8 +1336,6 @@ msim_check_inbox_cb(MsimSession *session body = msim_msg_get_dictionary(reply, "body"); g_return_if_fail(body != NULL); - notification = g_string_new(""); - old_inbox_status = session->inbox_status; n = 0; @@ -3009,7 +3012,7 @@ msim_test_msg(void) msg = msim_msg_new(NULL); /* Create a new, empty message. */ /* Append some new elements. */ - msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3)); + msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len("XXX", 3)); msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v1")); msg = msim_msg_append(msg, "k1", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(42)); msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v43"));