changeset 12126:35c4797c5c57

[gaim-migrate @ 14426] SF Patch #1359761, from sadrul "This patch plugs some memory leaks in a few places ragarding gaim_find_buddies. It also changes the call to gaim_find_buddy in a couple of places that only needs one buddy." I also fixed a case of g_free()ing a const char * in the sametime prpl. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Fri, 18 Nov 2005 12:05:40 +0000
parents 3c1bac709234
children 944c97d11bb1
files src/protocols/msn/slp.c src/protocols/novell/novell.c src/protocols/sametime/sametime.c src/prpl.c
diffstat 4 files changed, 34 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/slp.c	Fri Nov 18 07:23:29 2005 +0000
+++ b/src/protocols/msn/slp.c	Fri Nov 18 12:05:40 2005 +0000
@@ -848,7 +848,6 @@
 {
 	GaimAccount *account;
 	GaimBuddy *buddy;
-	GSList *sl;
 	const char *old;
 	const char *new;
 
@@ -856,13 +855,10 @@
 
 	account = gaim_connection_get_account(gc);
 
-	sl = gaim_find_buddies(account, msn_object_get_creator(obj));
-
-	if (sl == NULL)
+	buddy = gaim_find_buddy(account, msn_object_get_creator(obj));
+	if (buddy == NULL)
 		return FALSE;
 
-	buddy = (GaimBuddy *)sl->data;
-
 	old = gaim_blist_node_get_string((GaimBlistNode *)buddy, "icon_checksum");
 	new = msn_object_get_sha1c(obj);
 
@@ -930,18 +926,19 @@
 	if (obj == NULL)
 	{
 		/* It seems the user has not set a msnobject */
-		GSList *sl;
+		GSList *sl, *list;
 
 		/* TODO: I think we need better buddy icon core functions. */
 		gaim_buddy_icons_set_for_user(account, user->passport, NULL, -1);
 
-		sl = gaim_find_buddies(account, user->passport);
+		list = gaim_find_buddies(account, user->passport);
 
-		for (; sl != NULL; sl = sl->next)
+		for (sl = list; sl != NULL; sl = sl->next)
 		{
 			GaimBuddy *buddy = (GaimBuddy *)sl->data;
 			gaim_blist_node_remove_setting((GaimBlistNode*)buddy, "icon_checksum");
 		}
+		g_slist_free(list);
 
 		return;
 	}
@@ -977,7 +974,7 @@
 	MsnUserList *userlist;
 	const char *info;
 	GaimAccount *account;
-	GSList *sl;
+	GSList *sl, *list;
 
 	g_return_if_fail(slpcall != NULL);
 
@@ -993,13 +990,14 @@
 	gaim_buddy_icons_set_for_user(account, slpcall->slplink->remote_user,
 								  (void *)data, size);
 
-	sl = gaim_find_buddies(account, slpcall->slplink->remote_user);
+	list = gaim_find_buddies(account, slpcall->slplink->remote_user);
 
-	for (; sl != NULL; sl = sl->next)
+	for (sl = list; sl != NULL; sl = sl->next)
 	{
 		GaimBuddy *buddy = (GaimBuddy *)sl->data;
 		gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info);
 	}
+	g_slist_free(list);
 
 #if 0
 	/* Free one window slot */
@@ -1075,7 +1073,7 @@
 		gchar *data = NULL;
 		gsize len = 0;
 		const char *my_info = NULL;
-		GSList *sl;
+		GSList *sl, *list;
 
 #ifdef MSN_DEBUG_UD
 		gaim_debug_info("msn", "Requesting our own user display\n");
@@ -1096,13 +1094,14 @@
 		gaim_buddy_icons_set_for_user(account, user->passport, (void *)data, len);
 		g_free(data);
 
-		sl = gaim_find_buddies(account, user->passport);
+		list = gaim_find_buddies(account, user->passport);
 
-		for (; sl != NULL; sl = sl->next)
+		for (sl = list; sl != NULL; sl = sl->next)
 		{
 			GaimBuddy *buddy = (GaimBuddy *)sl->data;
 			gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info);
 		}
+		g_slist_free(list);
 
 		/* Free one window slot */
 		session->userlist->buddy_icon_window++;
--- a/src/protocols/novell/novell.c	Fri Nov 18 07:23:29 2005 +0000
+++ b/src/protocols/novell/novell.c	Fri Nov 18 12:05:40 2005 +0000
@@ -151,6 +151,7 @@
 					_update_buddy_status(buddy, status, time(0));
 				}
 			}
+			g_slist_free(buddies);
 		}
 
 	} else {
--- a/src/protocols/sametime/sametime.c	Fri Nov 18 07:23:29 2005 +0000
+++ b/src/protocols/sametime/sametime.c	Fri Nov 18 12:05:40 2005 +0000
@@ -1681,7 +1681,7 @@
   struct mwGaimPluginData *pd;
   GaimAccount *acct;
   GaimConversation *conv;
-  GSList *buddies;
+  GaimBuddy *buddy;
   char *who = from->user_id;
   char *msg;
   
@@ -1690,10 +1690,9 @@
   conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, who, acct);
   if(! conv) conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, acct, who);
 
-  buddies = gaim_find_buddies(acct, who);
-  if(buddies) {
-    who = (char *) gaim_buddy_get_contact_alias(buddies->data);
-    g_slist_free(buddies);
+  buddy = gaim_find_buddy(acct, who);
+  if(buddy) {
+    who = g_strdup(gaim_buddy_get_contact_alias(buddy));
   }
 
   who = g_strdup_printf(_("Announcement from %s"), who);
--- a/src/prpl.c	Fri Nov 18 07:23:29 2005 +0000
+++ b/src/prpl.c	Fri Nov 18 12:05:40 2005 +0000
@@ -188,40 +188,43 @@
 gaim_prpl_got_user_idle(GaimAccount *account, const char *name,
 		gboolean idle, time_t idle_time)
 {
-	GSList *l;
+	GSList *list, *iter;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(name    != NULL);
 	g_return_if_fail(gaim_account_is_connected(account));
 
-	for (l = gaim_find_buddies(account, name); l != NULL; l = l->next)
+	list = gaim_find_buddies(account, name);
+	for (iter = list; iter != NULL; iter = iter->next)
 	{
 		GaimBuddy *buddy;
 		GaimPresence *presence;
 
-		buddy = (GaimBuddy *)l->data;
+		buddy = (GaimBuddy *)iter->data;
 
 		presence = gaim_buddy_get_presence(buddy);
 
 		gaim_presence_set_idle(presence, idle, idle_time);
 	}
+	g_slist_free(list);
 }
 
 void
 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name,
 		time_t login_time)
 {
-	GSList *l;
+	GSList *list, *iter;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(name    != NULL);
 
-	for (l = gaim_find_buddies(account, name); l != NULL; l = l->next)
+	list = gaim_find_buddies(account, name);
+	for (iter = list; iter != NULL; iter = iter->next)
 	{
 		GaimBuddy *buddy;
 		GaimPresence *presence;
 
-		buddy = (GaimBuddy *)l->data;
+		buddy = (GaimBuddy *)iter->data;
 
 		if (login_time == 0)
 			login_time = time(NULL);
@@ -230,27 +233,29 @@
 
 		gaim_presence_set_login_time(presence, login_time);
 	}
+	g_slist_free(list);
 }
 
 void
 gaim_prpl_got_user_status(GaimAccount *account, const char *name,
 		const char *status_id, const char *attr_id, ...)
 {
-	GSList *l;
+	GSList *list, *iter;
 
 	g_return_if_fail(account   != NULL);
 	g_return_if_fail(name      != NULL);
 	g_return_if_fail(status_id != NULL);
 	g_return_if_fail(gaim_account_is_connected(account));
 
-	for (l = gaim_find_buddies(account, name); l != NULL; l = l->next)
+	list = gaim_find_buddies(account, name);
+	for (iter = list; iter != NULL; iter = iter->next)
 	{
 		GaimBuddy *buddy;
 		GaimPresence *presence;
 		GaimStatus *status;
 		GaimStatus *old_status;
 
-		buddy = (GaimBuddy *)l->data;
+		buddy = (GaimBuddy *)iter->data;
 		presence = gaim_buddy_get_presence(buddy);
 		status   = gaim_presence_get_status(presence, status_id);
 
@@ -276,6 +281,7 @@
 		gaim_presence_set_status_active(presence, status_id, TRUE);
 		gaim_blist_update_buddy_status(buddy, old_status);
 	}
+	g_slist_free(list);
 }
 
 void