diff libpurple/protocols/myspace/myspace.c @ 29365:52fffd4cdd62

Make sure we free myspace buddy proto_data when we disconnect. I believe this fixes a memory leak and a crash when signing off while we're fetching a buddy icon
author Mark Doliner <mark@kingant.net>
date Thu, 04 Feb 2010 22:41:02 +0000
parents 5a367a023195
children e137c1fc216a
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Thu Feb 04 22:37:21 2010 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Thu Feb 04 22:41:02 2010 +0000
@@ -2264,6 +2264,13 @@
 	}
 }
 
+static void
+msim_buddy_free(PurpleBuddy *buddy)
+{
+	msim_user_free(purple_buddy_get_protocol_data(buddy));
+	purple_buddy_set_protocol_data(buddy, NULL);
+}
+
 /**
  * Close the connection.
  *
@@ -2272,8 +2279,20 @@
 static void
 msim_close(PurpleConnection *gc)
 {
+	GSList *buddies;
 	MsimSession *session;
 
+	/*
+	 * Free our protocol-specific buddy data.  It almost seems like libpurple
+	 * should call our buddy_free prpl callback so that we don't need to do
+	 * this... but it doesn't, so we do.
+	 */
+	buddies = purple_blist_get_buddies();
+	while (buddies != NULL) {
+		msim_buddy_free(buddies->data);
+		buddies = g_slist_delete_link(buddies, buddies);
+	}
+
 	if (gc == NULL) {
 		return;
 	}
@@ -2734,13 +2753,6 @@
 	msim_update_blocklist_for_buddy(session, name, TRUE, FALSE);
 }
 
-static void
-msim_buddy_free(PurpleBuddy *buddy)
-{
-	msim_user_free(purple_buddy_get_protocol_data(buddy));
-	purple_buddy_set_protocol_data(buddy, NULL);
-}
-
 /**
  * Remove a buddy from the user's buddy list.
  */