pidgin: 90a5f93a: A couple of memory leak fixes.

sadrul at pidgin.im sadrul at pidgin.im
Wed Dec 31 22:15:41 EST 2008


-----------------------------------------------------------------
Revision: 90a5f93a4d969a242378420c9e060c5d49e35917
Ancestor: 08eb4eb016e65c9a5fa6e226fd0fb4c9ebadcc31
Author: sadrul at pidgin.im
Date: 2009-01-01T03:12:56
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/90a5f93a4d969a242378420c9e060c5d49e35917

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

ChangeLog: 

A couple of memory leak fixes.

-------------- next part --------------
============================================================
--- libpurple/protocols/myspace/myspace.c	9a16e6dcedc4af27fa1fd34709aa84c0f1c60560
+++ libpurple/protocols/myspace/myspace.c	fbc92dbf6b0e3598b173a27046e88394eac9d924
@@ -211,7 +211,6 @@ msim_postprocess_outgoing(MsimSession *s
 			/* Don't have uid offhand - need to ask for it, and wait until hear back before sending. */
 			purple_debug_info("msim", ">>> msim_postprocess_outgoing: couldn't find username %s in blist\n",
 					username ? username : "(NULL)");
-			/* TODO: where is cloned message freed? Should be in _cb. */
 			msim_lookup_user(session, username, msim_postprocess_outgoing_cb, msim_msg_clone(msg));
 			return TRUE;       /* not sure of status yet - haven't sent! */
 		}
@@ -1923,8 +1922,7 @@ msim_incoming_resolved(MsimSession *sess
 
 	msim_process(session, msg);
 
-	/* TODO: Free copy cloned from  msim_preprocess_incoming(). */
-	/* msim_msg_free(msg); */
+	msim_msg_free(msg);
 	msim_msg_free(body);
 }
 
@@ -2731,9 +2729,15 @@ msim_remove_buddy(PurpleConnection *gc, 
 	 * doesn't seem like it would be necessary, but the official client
 	 * does it)
 	 */
-	if (!msim_update_blocklist_for_buddy(session, buddy->name, FALSE, FALSE))
+	if (!msim_update_blocklist_for_buddy(session, buddy->name, FALSE, FALSE)) {
 		purple_notify_error(NULL, NULL,
 				_("Failed to remove buddy"), _("blocklist command failed"));
+		return;
+	}
+	if (buddy->proto_data) {
+		msim_user_free(buddy->proto_data);
+		buddy->proto_data = NULL;
+	}
 }
 
 /**
@@ -2823,6 +2827,13 @@ msim_rem_deny(PurpleConnection *gc, cons
 	msim_update_blocklist_for_buddy(session, name, FALSE, FALSE);
 }
 
+static void
+msim_buddy_free(PurpleBuddy *buddy)
+{
+	msim_user_free(buddy->proto_data);
+	buddy->proto_data = NULL;
+}
+
 /**
  * Returns a string of a username in canonical form. Basically removes all the
  * spaces, lowercases the string, and looks up user IDs to usernames.
@@ -3039,7 +3050,7 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL,              /* alias_buddy */
 	NULL,              /* group_buddy */
 	NULL,              /* rename_group */
-	NULL,              /* buddy_free */
+	msim_buddy_free,   /* buddy_free */
 	NULL,              /* convo_closed */
 	msim_normalize,    /* normalize */
 	NULL,              /* set_buddy_icon */
============================================================
--- libpurple/protocols/myspace/user.c	c2a79a2f3df397e594a0ab8e288813f952e59787
+++ libpurple/protocols/myspace/user.c	94aa2d0dd13991adbc173f59e3c9e26ac5f8b7bc
@@ -55,10 +55,9 @@ msim_get_user_from_buddy(PurpleBuddy *bu
 	if (!buddy->proto_data) {
 		/* No MsimUser for this buddy; make one. */
 
-		/* TODO: where is this freed? */
 		user = g_new0(MsimUser, 1);
 		user->buddy = buddy;
-		user->id = purple_blist_node_get_int(&buddy->node, "UserID");
+		user->id = purple_blist_node_get_int((PurpleBlistNode*)buddy, "UserID");
 		buddy->proto_data = (gpointer)user;
 	}
 
@@ -67,6 +66,23 @@ msim_get_user_from_buddy(PurpleBuddy *bu
 	return user;
 }
 
+void msim_user_free(MsimUser *user)
+{
+	if (!user)
+		return;
+
+	g_free(user->client_info);
+	g_free(user->gender);
+	g_free(user->location);
+	g_free(user->headline);
+	g_free(user->display_name);
+	g_free(user->username);
+	g_free(user->band_name);
+	g_free(user->song_name);
+	g_free(user->image_url);
+	g_free(user);
+}
+
 /**
  * Find and return an MsimUser * representing a user on the buddy list, or NULL.
  */
============================================================
--- libpurple/protocols/myspace/user.h	8c7f959c1a55e122cd4ad2299098b430fab1746f
+++ libpurple/protocols/myspace/user.h	d0f7d03ca835197dd945a6e5eec6fdcb2fb2137b
@@ -47,6 +47,7 @@ MsimUser *msim_get_user_from_buddy(Purpl
 typedef void (*MSIM_USER_LOOKUP_CB)(MsimSession *session, const MsimMessage *userinfo, gpointer data);
 
 MsimUser *msim_get_user_from_buddy(PurpleBuddy *buddy);
+void msim_user_free(MsimUser *user);
 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, const MsimMessage *msg, MsimUser *user);


More information about the Commits mailing list