diff libpurple/protocols/myspace/user.c @ 20982:aee8d876fed1

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.
author Evan Schoenberg <evan.s@dreskin.net>
date Thu, 18 Oct 2007 12:01:41 +0000
parents 61045691aa72
children 87c9d114864b
line wrap: on
line diff
--- a/libpurple/protocols/myspace/user.c	Thu Oct 18 07:49:20 2007 +0000
+++ b/libpurple/protocols/myspace/user.c	Thu Oct 18 12:01:41 2007 +0000
@@ -99,10 +99,12 @@
 
 	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 @@
 		/* 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);