changeset 31711:feb50c34ec46

Fix a memleak in the MSN prpl when removing a buddy from your buddy list. We needed to call msn_user_unref() after calling msn_userlist_remove_user() I chose to fix this by changing msn_userlist_add_user() and msn_userlist_remove_user() to incremend and decrement the reference counter themselves--after all, they ARE the ones who add/remove a reference to the MsnUser struct. Conceptually I thought this made the most sense.
author Mark Doliner <mark@kingant.net>
date Mon, 28 Feb 2011 07:12:27 +0000
parents 087395608ed9
children 8fc25b77295a
files libpurple/protocols/msn/msn.c libpurple/protocols/msn/session.c libpurple/protocols/msn/user.h libpurple/protocols/msn/userlist.c
diffstat 4 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c	Mon Feb 28 06:53:53 2011 +0000
+++ b/libpurple/protocols/msn/msn.c	Mon Feb 28 07:12:27 2011 +0000
@@ -1765,6 +1765,7 @@
 			user = user2;
 		} else {
 			msn_userlist_add_user(userlist, user);
+			msn_user_unref(user);
 		}
 
 		msn_user_set_network(user, network);
--- a/libpurple/protocols/msn/session.c	Mon Feb 28 06:53:53 2011 +0000
+++ b/libpurple/protocols/msn/session.c	Mon Feb 28 07:12:27 2011 +0000
@@ -46,7 +46,7 @@
 
 	session->user = msn_user_new(session->userlist,
 								 purple_account_get_username(account), NULL);
-	msn_userlist_add_user(session->userlist, msn_user_ref(session->user));
+	msn_userlist_add_user(session->userlist, session->user);
 	session->oim = msn_oim_new(session);
 
 	session->protocol_ver = 0;
--- a/libpurple/protocols/msn/user.h	Mon Feb 28 06:53:53 2011 +0000
+++ b/libpurple/protocols/msn/user.h	Mon Feb 28 07:12:27 2011 +0000
@@ -149,7 +149,7 @@
  * @param passport     The initial passport.
  * @param stored_name  The initial stored name.
  *
- * @return A new user structure.
+ * @return A new user structure.  It will have a reference count of 1.
  */
 MsnUser *msn_user_new(MsnUserList *userlist, const char *passport,
 					  const char *friendly_name);
@@ -164,7 +164,8 @@
 MsnUser *msn_user_ref(MsnUser *user);
 
 /**
- * Decrement the reference count.
+ * Decrement the reference count.  When the count reaches 0 the object is
+ * automatically freed.
  *
  * @param user 	The user
  */
--- a/libpurple/protocols/msn/userlist.c	Mon Feb 28 06:53:53 2011 +0000
+++ b/libpurple/protocols/msn/userlist.c	Mon Feb 28 07:12:27 2011 +0000
@@ -245,6 +245,7 @@
 	{
 		user = msn_user_new(userlist, passport, friendly_name);
 		msn_userlist_add_user(userlist, user);
+		msn_user_unref(user);
 	} else {
 		msn_user_set_friendly_name(user, friendly_name);
 	}
@@ -254,6 +255,7 @@
 void
 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user)
 {
+	msn_user_ref(user);
 	userlist->users = g_list_prepend(userlist->users, user);
 }
 
@@ -261,6 +263,7 @@
 msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user)
 {
 	userlist->users = g_list_remove(userlist->users, user);
+	msn_user_unref(user);
 }
 
 MsnUser *