im.pidgin.pidgin: 3bee1aee40b5389caacd65f686618708d5bc65c8

evands at pidgin.im evands at pidgin.im
Thu Oct 18 08:05:49 EDT 2007


-----------------------------------------------------------------
Revision: 3bee1aee40b5389caacd65f686618708d5bc65c8
Ancestor: 8e81ccec879f9cfbd8fc282b703803c98e150ff7
Author: evands at pidgin.im
Date: 2007-10-18T12:01:41
Branch: im.pidgin.pidgin

Modified files:
        libpurple/protocols/myspace/myspace.c
        libpurple/protocols/myspace/user.c
        libpurple/protocols/myspace/user.h

ChangeLog: 

When getting info on a myspace user not on the buddy list, a temporary
PurpleBuddy is needed so that the data can be associated properly. This
fixes a bug wherein the profile link went to http://myspace.com/0 for all
buddies not on the list. A check against that uid being 0 has also been added
to avoid displaying junk data.

Such temporary MsimUser objects (note that the temporariness of MsimUser
objects is unchanged; a temporary PurpleBuddy has just been added to go with
it) are destroyed before a delayed callback can be triggerred. This means that
we can not request a buddy icon on that object, because we will end up with
a pointer to freed data in the callback some time in the future. This fixes
a crash when getting info on a non-buddy list buddy (which for reasons I can't
pinpoint was most likely if the username contained capital letters).

A reference counting system for MsimUser objects would fix this but is a
significantly more complex solution. 

-------------- next part --------------
============================================================
--- libpurple/protocols/myspace/myspace.c	d8502c3ea4015fc5905ec5f1128cfa764454406c
+++ libpurple/protocols/myspace/myspace.c	ff576b5d39896ef47ac232d7e82b837f92865aa6
@@ -935,7 +935,6 @@ msim_get_info_cb(MsimSession *session, M
 	gchar *username;
 	PurpleNotifyUserInfo *user_info;
 	MsimUser *user;
-	gboolean temporary_user;
 
 	g_return_if_fail(MSIM_SESSION_VALID(session));
 
@@ -957,10 +956,14 @@ msim_get_info_cb(MsimSession *session, M
 
 	if (!user) {
 		/* User isn't on blist, create a temporary user to store info. */
-		temporary_user = TRUE;
+		PurpleBuddy *buddy;
+
 		user = g_new0(MsimUser, 1);
-	} else {
-		temporary_user = FALSE;
+		user->temporary_user = TRUE;
+
+		buddy = purple_buddy_new(session->account, username, NULL);
+		user->buddy = buddy;
+		buddy->proto_data = (gpointer)user;
 	}
 
 	/* Update user structure with new information */
@@ -976,7 +979,8 @@ msim_get_info_cb(MsimSession *session, M
 
 	purple_notify_user_info_destroy(user_info);
 
-	if (temporary_user) {
+	if (user->temporary_user) {
+		purple_blist_remove_buddy(user->buddy);
 		g_free(user->client_info);
 		g_free(user->gender);
 		g_free(user->location);
@@ -1452,7 +1456,7 @@ msim_check_newer_version_cb(PurpleUtilFe
 	purple_debug_info("msim", "data=%s\n", data->str
 			? data->str : "(NULL)");
 
-	/* url_text is variable=data\n... */
+	/* url_text is variable=data\n...†*/
 
 	/* Check FILEVER, 1.0.716.0. 716 is build, MSIM_CLIENT_VERSION */
 	/* New (english) version can be downloaded from SETUPURL+SETUPFILE */
============================================================
--- libpurple/protocols/myspace/user.c	7b2c5dd1ac71ad9a756d53486dd35842accbfba3
+++ libpurple/protocols/myspace/user.c	95316bf89e8f7e2f818182d35805f65cf0039717
@@ -99,10 +99,12 @@ msim_append_user_info(MsimSession *sessi
 
 	if (full) {
 		/* TODO: link to username, if available */
-		char *profile = g_strdup_printf("<a href=\"http://myspace.com/%d\">http://myspace.com/%d</a>",
-				uid, uid);
-		purple_notify_user_info_add_pair(user_info, _("Profile"), profile);
-		g_free(profile);
+		if (uid) {
+			char *profile = g_strdup_printf("<a href=\"http://myspace.com/%d\">http://myspace.com/%d</a>",
+											uid, uid);
+			purple_notify_user_info_add_pair(user_info, _("Profile"), profile);
+			g_free(profile);
+		}
 	}
 
 
@@ -201,6 +203,14 @@ msim_store_user_info_each(const gchar *k
 		/* Ignore because PurpleBuddy knows this already */
 		g_free(value_str);
 	} else if (g_str_equal(key_str, "ImageURL") || g_str_equal(key_str, "AvatarURL")) {
+		if (user->temporary_user) {
+			/* This user will be destroyed soon; don't try to look up its image or avatar, 
+			 * since that won't return immediately and we will end up accessing freed data.
+			 */
+			g_free(value_str);
+			return;
+		}
+		
 		const gchar *previous_url;
 
 		g_free(user->image_url);
============================================================
--- libpurple/protocols/myspace/user.h	3ebee0690621ae3e7e4f46b265ca6c04f12245d4
+++ libpurple/protocols/myspace/user.h	6583df03164b0ae01faacba559a10b7e51118c45
@@ -38,6 +38,7 @@ typedef struct _MsimUser
 	gchar *band_name, *song_name;
 	gchar *image_url;
 	guint last_image_updated;
+	gboolean temporary_user;
 } MsimUser;
 
 /* Callback function pointer type for when a user's information is received, 


More information about the Commits mailing list