Mercurial > pidgin
changeset 20658:7efdc052539d
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.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 26 Sep 2007 07:25:22 +0000 |
parents | c2c263d47534 |
children | 94a64640af5d |
files | libpurple/protocols/myspace/markup.c libpurple/protocols/myspace/message.c libpurple/protocols/myspace/myspace.c |
diffstat | 3 files changed, 21 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/markup.c Tue Sep 25 21:16:55 2007 +0000 +++ b/libpurple/protocols/myspace/markup.c Wed Sep 26 07:25:22 2007 +0000 @@ -258,8 +258,8 @@ } - *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 @@ 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. */
--- a/libpurple/protocols/myspace/message.c Tue Sep 25 21:16:55 2007 +0000 +++ b/libpurple/protocols/myspace/message.c Wed Sep 26 07:25:22 2007 +0000 @@ -80,7 +80,7 @@ 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 @@ 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 @@ ++i; } - string = gs->str; + string = g_string_free(gs, FALSE); break; default: @@ -798,7 +798,7 @@ 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 @@ 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;
--- a/libpurple/protocols/myspace/myspace.c Tue Sep 25 21:16:55 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.c Wed Sep 26 07:25:22 2007 +0000 @@ -43,7 +43,7 @@ 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 *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 @@ 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 @@ "status", MSIM_TYPE_INTEGER, 100, "id", MSIM_TYPE_INTEGER, 1, NULL); + + g_free(response); + + return ret; } /** @@ -389,7 +394,7 @@ * @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 @@ 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 @@ *response_len = data_out_len; - return (const gchar *)data_out; + return (gchar *)data_out; } /** @@ -1297,7 +1303,6 @@ 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 @@ 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 @@ 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"));