pidgin: a43b4cbe: Fix a memleak in the MSN prpl when remov...

markdoliner at pidgin.im markdoliner at pidgin.im
Mon Feb 28 02:28:23 EST 2011


----------------------------------------------------------------------
Revision: a43b4cbedbecdd778fcc46ab93b13b1c8f0a326b
Parent:   d3c73d69688687fb6bc62852836a8e0bd1b51382
Author:   markdoliner at pidgin.im
Date:     02/28/11 02:12:27
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a43b4cbedbecdd778fcc46ab93b13b1c8f0a326b

Changelog: 

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.

Changes against parent d3c73d69688687fb6bc62852836a8e0bd1b51382

  patched  libpurple/protocols/msn/msn.c
  patched  libpurple/protocols/msn/session.c
  patched  libpurple/protocols/msn/user.h
  patched  libpurple/protocols/msn/userlist.c

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msn.c	5776381396d6ea737e23e1b39a826f90d9306e2d
+++ libpurple/protocols/msn/msn.c	80cf4a20bb82ff87d5c4266485f7677b84e6062f
@@ -1765,6 +1765,7 @@ add_pending_buddy(MsnSession *session,
 			user = user2;
 		} else {
 			msn_userlist_add_user(userlist, user);
+			msn_user_unref(user);
 		}
 
 		msn_user_set_network(user, network);
============================================================
--- libpurple/protocols/msn/session.c	97c71478eb63f3602c4e893b4ddd3fbaec575acc
+++ libpurple/protocols/msn/session.c	9b8bcdf10308352fa6e55d0484062168f4386613
@@ -46,7 +46,7 @@ msn_session_new(PurpleAccount *account)
 
 	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;
============================================================
--- libpurple/protocols/msn/user.h	0d8b8dfd862734da629d31ec1ef52fc14b122e15
+++ libpurple/protocols/msn/user.h	5aae46f7ca049d919306cd2922197849b8517422
@@ -149,7 +149,7 @@ typedef struct MsnUserEndpoint {
  * @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);
 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
  */
============================================================
--- libpurple/protocols/msn/userlist.c	80bafe4657ab7fa204289a0a6ac319caf9201769
+++ libpurple/protocols/msn/userlist.c	5a7275f182155b4030b83239285c9a5fa1123993
@@ -245,6 +245,7 @@ msn_userlist_find_add_user(MsnUserList *
 	{
 		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 @@ msn_userlist_add_user(MsnUserList *userl
 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 *us
 msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user)
 {
 	userlist->users = g_list_remove(userlist->users, user);
+	msn_user_unref(user);
 }
 
 MsnUser *


More information about the Commits mailing list