Mercurial > pidgin
changeset 24799:c044eb54b7ac
Fix a leak in myspace prpl.
In myspace.c:msim_process_reply, the clone of 'msg' sent to the callbacks
were never freed. Also, do not unnecessarily dup a static string (which
needs to be marked for translation after the string freeze).
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 17 Dec 2008 20:50:49 +0000 |
parents | a8643ca8d2e0 |
children | ffe3e41dfade 759dbafdc74a |
files | libpurple/protocols/myspace/message.c libpurple/protocols/myspace/message.h libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/user.c libpurple/protocols/myspace/user.h |
diffstat | 5 files changed, 31 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c Wed Dec 17 18:36:31 2008 +0000 +++ b/libpurple/protocols/myspace/message.c Wed Dec 17 20:50:49 2008 +0000 @@ -401,7 +401,7 @@ * */ static GList * -msim_msg_get_node(MsimMessage *msg, const gchar *name) +msim_msg_get_node(const MsimMessage *msg, const gchar *name) { GList *node; @@ -410,7 +410,7 @@ } /* Linear search for the given name. O(n) but n is small. */ - for (node = msg; node != NULL; node = g_list_next(node)) { + for (node = (GList*)msg; node != NULL; node = g_list_next(node)) { MsimMessageElement *elem; elem = (MsimMessageElement *)node->data; @@ -1066,7 +1066,7 @@ * another msim_msg_get_* that converts the data to what type you want. */ MsimMessageElement * -msim_msg_get(MsimMessage *msg, const gchar *name) +msim_msg_get(const MsimMessage *msg, const gchar *name) { GList *node; @@ -1115,7 +1115,7 @@ * This function unescapes the string for you, if needed. */ gchar * -msim_msg_get_string(MsimMessage *msg, const gchar *name) +msim_msg_get_string(const MsimMessage *msg, const gchar *name) { MsimMessageElement *elem; @@ -1185,7 +1185,7 @@ * Return an element as a new list. Caller frees with msim_msg_list_free(). */ GList * -msim_msg_get_list(MsimMessage *msg, const gchar *name) +msim_msg_get_list(const MsimMessage *msg, const gchar *name) { MsimMessageElement *elem; @@ -1279,7 +1279,7 @@ * Return an element as a new dictionary. Caller frees with msim_msg_free(). */ MsimMessage * -msim_msg_get_dictionary(MsimMessage *msg, const gchar *name) +msim_msg_get_dictionary(const MsimMessage *msg, const gchar *name) { MsimMessageElement *elem; @@ -1321,7 +1321,7 @@ * be converted handled correctly, for example. */ guint -msim_msg_get_integer(MsimMessage *msg, const gchar *name) +msim_msg_get_integer(const MsimMessage *msg, const gchar *name) { MsimMessageElement *elem; @@ -1398,7 +1398,7 @@ * @return TRUE if successful, FALSE if not. */ gboolean -msim_msg_get_binary(MsimMessage *msg, const gchar *name, +msim_msg_get_binary(const MsimMessage *msg, const gchar *name, gchar **binary_data, gsize *binary_length) { MsimMessageElement *elem;
--- a/libpurple/protocols/myspace/message.h Wed Dec 17 18:36:31 2008 +0000 +++ b/libpurple/protocols/myspace/message.h Wed Dec 17 20:50:49 2008 +0000 @@ -93,14 +93,14 @@ MsimMessage *msim_parse(const gchar *raw); -MsimMessageElement *msim_msg_get(MsimMessage *msg, const gchar *name); +MsimMessageElement *msim_msg_get(const MsimMessage *msg, const gchar *name); /* Retrieve data by name */ -gchar *msim_msg_get_string(MsimMessage *msg, const gchar *name); -GList *msim_msg_get_list(MsimMessage *msg, const gchar *name); -MsimMessage *msim_msg_get_dictionary(MsimMessage *msg, const gchar *name); -guint msim_msg_get_integer(MsimMessage *msg, const gchar *name); -gboolean msim_msg_get_binary(MsimMessage *msg, const gchar *name, gchar **binary_data, gsize *binary_length); +gchar *msim_msg_get_string(const MsimMessage *msg, const gchar *name); +GList *msim_msg_get_list(const MsimMessage *msg, const gchar *name); +MsimMessage *msim_msg_get_dictionary(const MsimMessage *msg, const gchar *name); +guint msim_msg_get_integer(const MsimMessage *msg, const gchar *name); +gboolean msim_msg_get_binary(const MsimMessage *msg, const gchar *name, gchar **binary_data, gsize *binary_length); /* Retrieve data by element (MsimMessageElement *), returned from msim_msg_get() */ gchar *msim_msg_get_string_from_element(MsimMessageElement *elem);
--- a/libpurple/protocols/myspace/myspace.c Wed Dec 17 18:36:31 2008 +0000 +++ b/libpurple/protocols/myspace/myspace.c Wed Dec 17 20:50:49 2008 +0000 @@ -112,7 +112,7 @@ * _uid_before: string, name of field before field to insert, or NULL for end */ static void -msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo, +msim_postprocess_outgoing_cb(MsimSession *session, const MsimMessage *userinfo, gpointer data) { gchar *uid_field_name, *uid_before, *username; @@ -829,7 +829,7 @@ * Handle mail reply checks. */ static void -msim_check_inbox_cb(MsimSession *session, MsimMessage *reply, gpointer data) +msim_check_inbox_cb(MsimSession *session, const MsimMessage *reply, gpointer data) { MsimMessage *body; guint old_inbox_status; @@ -958,7 +958,7 @@ * @param data An MsimMessage * of the contact information. Will be freed. */ static void -msim_add_contact_from_server_cb(MsimSession *session, MsimMessage *user_lookup_info, gpointer data) +msim_add_contact_from_server_cb(MsimSession *session, const MsimMessage *user_lookup_info, gpointer data) { MsimMessage *contact_info, *user_lookup_info_body; PurpleGroup *group; @@ -1094,7 +1094,7 @@ * Called when contact list is received from server. */ static void -msim_got_contact_list(MsimSession *session, MsimMessage *reply, gpointer user_data) +msim_got_contact_list(MsimSession *session, const MsimMessage *reply, gpointer user_data) { MsimMessage *body, *body_node; gchar *msg; @@ -1767,7 +1767,7 @@ if (cb) { purple_debug_info("msim", "msim_process_reply: calling callback now\n"); /* Clone message, so that the callback 'cb' can use it (needs to free it also). */ - cb(session, msim_msg_clone(msg), data); + cb(session, msg, data); g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid)); g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); } else { @@ -1898,7 +1898,7 @@ * @param data MsimMessage *, the message to attach information to. */ static void -msim_incoming_resolved(MsimSession *session, MsimMessage *userinfo, +msim_incoming_resolved(MsimSession *session, const MsimMessage *userinfo, gpointer data) { gchar *username; @@ -2340,7 +2340,7 @@ * Callback for msim_get_info(), for when user info is received. */ static void -msim_get_info_cb(MsimSession *session, MsimMessage *user_info_msg, +msim_get_info_cb(MsimSession *session, const MsimMessage *user_info_msg, gpointer data) { MsimMessage *msg; @@ -3087,7 +3087,7 @@ * Called when friends have been imported to buddy list on server. */ static void -msim_import_friends_cb(MsimSession *session, MsimMessage *reply, gpointer user_data) +msim_import_friends_cb(MsimSession *session, const MsimMessage *reply, gpointer user_data) { MsimMessage *body; gchar *completed;
--- a/libpurple/protocols/myspace/user.c Wed Dec 17 18:36:31 2008 +0000 +++ b/libpurple/protocols/myspace/user.c Wed Dec 17 20:50:49 2008 +0000 @@ -388,7 +388,7 @@ * is a no-op (and returns FALSE). */ gboolean -msim_store_user_info(MsimSession *session, MsimMessage *msg, MsimUser *user) +msim_store_user_info(MsimSession *session, const MsimMessage *msg, MsimUser *user) { gchar *username; MsimMessage *body, *body_node; @@ -592,9 +592,10 @@ /** * Called after username is set. */ -static void msim_username_is_set_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) +static void msim_username_is_set_cb(MsimSession *session, const MsimMessage *userinfo, gpointer data) { - gchar *username, *errmsg; + gchar *username; + const gchar *errmsg; MsimMessage *body; guint rid; @@ -610,7 +611,8 @@ uid = msim_msg_get_integer(userinfo, "uid"); lid = msim_msg_get_integer(userinfo, "lid"); body = msim_msg_get_dictionary(userinfo, "body"); - errmsg = g_strdup("An error occurred while trying to set the username.\n" + /* XXX: Mark for translation */ + errmsg = ("An error occurred while trying to set the username.\n" "Please try again, or visit http://editprofile.myspace.com/index.cfm?" "fuseaction=profile.username to set your username."); @@ -667,7 +669,6 @@ purple_debug_info("msim","username_is_set Error: Invalid cmd/dsn/lid combination"); purple_connection_error_reason(session->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, errmsg); } - g_free(errmsg); } /** @@ -751,7 +752,7 @@ * Now we have some real data to tell us the state of their requested username * \persistr\\cmd\257\dsn\5\uid\204084363\lid\7\rid\367\body\UserName=TheAlbinoRhino1\final\ */ -static void msim_username_is_available_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) +static void msim_username_is_available_cb(MsimSession *session, const MsimMessage *userinfo, gpointer data) { MsimMessage *msg; gchar *username;
--- a/libpurple/protocols/myspace/user.h Wed Dec 17 18:36:31 2008 +0000 +++ b/libpurple/protocols/myspace/user.h Wed Dec 17 20:50:49 2008 +0000 @@ -44,12 +44,12 @@ /* Callback function pointer type for when a user's information is received, * initiated from a user lookup. */ -typedef void (*MSIM_USER_LOOKUP_CB)(MsimSession *session, MsimMessage *userinfo, gpointer data); +typedef void (*MSIM_USER_LOOKUP_CB)(MsimSession *session, const MsimMessage *userinfo, gpointer data); MsimUser *msim_get_user_from_buddy(PurpleBuddy *buddy); MsimUser *msim_find_user(MsimSession *session, const gchar *username); void msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full); -gboolean msim_store_user_info(MsimSession *session, MsimMessage *msg, MsimUser *user); +gboolean msim_store_user_info(MsimSession *session, const MsimMessage *msg, MsimUser *user); gboolean msim_is_userid(const gchar *user); void msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data); void msim_set_username_cb(PurpleConnection *gc);