Mercurial > pidgin
diff libpurple/protocols/myspace/myspace.c @ 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 | b8962a8c5daa |
children | 324c25c2daad |
line wrap: on
line diff
--- 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"));