changeset 12373:508512caa22e

[gaim-migrate @ 14677] deryni pointed out that ggp_buddy_get_name leaks when the user isn't a buddy. I went to fix that and tweaked a bunch of code. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 06 Dec 2005 19:50:47 +0000
parents 188d7e79166b
children c57935373cc4
files src/protocols/gg/confer.c src/protocols/gg/gg.c src/protocols/gg/utils.c src/protocols/gg/utils.h
diffstat 4 files changed, 54 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/gg/confer.c	Tue Dec 06 19:22:13 2005 +0000
+++ b/src/protocols/gg/confer.c	Tue Dec 06 19:50:47 2005 +0000
@@ -56,17 +56,28 @@
 			continue;
 
 		if (g_list_find(chat->participants, str_uin) == NULL) {
+			GaimBuddy *buddy;
+
 			chat->participants = g_list_append(
 						chat->participants, str_uin);
 
 			conv = ggp_confer_find_by_name(gc, chat_name);
 
-			gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv),
-				ggp_buddy_get_name(gc, uin), NULL,
-				GAIM_CBFLAGS_NONE, TRUE);
+			buddy = gaim_find_buddy(gaim_connection_get_account(gc), str_uin);
+			if (buddy != NULL) {
+				gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv),
+							gaim_buddy_get_alias(buddy), NULL,
+							GAIM_CBFLAGS_NONE, TRUE);
+			} else {
+				gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv),
+							str_uin, NULL,
+							GAIM_CBFLAGS_NONE, TRUE);
+			}
 		}
 		break;
 	}
+
+	g_free(str_uin);
 }
 /* }}} */
 
@@ -74,35 +85,40 @@
 void ggp_confer_participants_add(GaimConnection *gc, const gchar *chat_name,
 				 const uin_t *recipients, int count)
 {
-	GaimConversation *conv;
 	GGPInfo *info = gc->proto_data;
-	GGPChat *chat;
 	GList *l;
-	int i;
-	gchar *uin;
 
 	for (l = info->chats; l != NULL; l = l->next) {
-		chat = l->data;
+		GGPChat *chat = l->data;
+		int i;
 
 		if (g_utf8_collate(chat->name, chat_name) != 0)
 			continue;
 
 		for (i = 0; i < count; i++) {
-			uin = g_strdup_printf("%lu", (unsigned long int)recipients[i]);
+			gchar *str_uin = g_strdup_printf("%lu", (unsigned long int)recipients[i]);
+			GaimConversation *conv;
+			GaimBuddy *buddy;
 
-			if (g_list_find(chat->participants, uin) != NULL) {
-				g_free(uin);
+			if (g_list_find(chat->participants, str_uin) != NULL) {
+				g_free(str_uin);
 				continue;
 			}
 
-			chat->participants = g_list_append(chat->participants, uin);
+			chat->participants = g_list_append(chat->participants, str_uin);
 			conv = ggp_confer_find_by_name(gc, chat_name);
 
-			gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv),
-				ggp_buddy_get_name(gc, recipients[i]),
-				NULL, GAIM_CBFLAGS_NONE, TRUE);
-
-			g_free(uin);
+			buddy = gaim_find_buddy(gaim_connection_get_account(gc), str_uin);
+			if (buddy != NULL) {
+				gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv),
+							gaim_buddy_get_alias(buddy), NULL,
+							GAIM_CBFLAGS_NONE, TRUE);
+			} else {
+				gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv),
+							str_uin, NULL,
+							GAIM_CBFLAGS_NONE, TRUE);
+			}
+			g_free(str_uin);
 		}
 		break;
 	}
@@ -115,25 +131,27 @@
 {
 	GGPInfo *info = gc->proto_data;
 	GGPChat *chat = NULL;
-	GList *l, *m;
-	int i;
-	int maches;
+	GList *l;
+	int matches;
 
 	g_return_val_if_fail(info->chats != NULL, NULL);
 
 	for (l = info->chats; l != NULL; l = l->next) {
+		GList *m;
+
 		chat = l->data;
-		maches = 0;
+		matches = 0;
 
 		for (m = chat->participants; m != NULL; m = m->next) {
 			uin_t p = ggp_str_to_uin(m->data);
+			int i;
 
 			for (i = 0; i < count; i++)
 				if (p == recipients[i])
-					maches++;
+					matches++;
 		}
 
-		if (maches == count)
+		if (matches == count)
 			break;
 
 		chat = NULL;
--- a/src/protocols/gg/gg.c	Tue Dec 06 19:22:13 2005 +0000
+++ b/src/protocols/gg/gg.c	Tue Dec 06 19:50:47 2005 +0000
@@ -1070,8 +1070,6 @@
 	gchar *from;
 	gchar *msg;
 	gchar *tmp;
-	const char *chat_name;
-	int chat_id;
 
 	from = g_strdup_printf("%lu", (unsigned long int)ev->event.msg.sender);
 
@@ -1079,6 +1077,7 @@
 			      "CP1250", "UTF-8");
 	gaim_str_strip_char(msg, '\r');
 	tmp = g_markup_escape_text(msg, -1);
+	g_free(msg);
 
 	gaim_debug_info("gg", "msg form (%s): %s (class = %d; rcpt_count = %d)\n",
 			from, tmp, ev->event.msg.msgclass,
@@ -1087,6 +1086,10 @@
 	if (ev->event.msg.recipients_count == 0) {
 		serv_got_im(gc, from, tmp, 0, ev->event.msg.time);
 	} else {
+		const char *chat_name;
+		int chat_id;
+		char *buddy_name;
+
 		chat_name = ggp_confer_find_by_participants(gc,
 				ev->event.msg.recipients,
 				ev->event.msg.recipients_count);
@@ -1103,11 +1106,12 @@
 		}
 		conv = ggp_confer_find_by_name(gc, chat_name);
 		chat_id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
-		serv_got_chat_in(gc, chat_id,
-				 ggp_buddy_get_name(gc, ev->event.msg.sender),
+
+		buddy_name = ggp_buddy_get_name(gc, ev->event.msg.sender);
+		serv_got_chat_in(gc, chat_id, buddy_name,
 				 0, msg, ev->event.msg.time);
+		g_free(buddy_name);
 	}
-	g_free(msg);
 	g_free(tmp);
 	g_free(from);
 }
--- a/src/protocols/gg/utils.c	Tue Dec 06 19:22:13 2005 +0000
+++ b/src/protocols/gg/utils.c	Tue Dec 06 19:50:47 2005 +0000
@@ -82,8 +82,8 @@
 }
 /* }}} */
 
-/* const *char ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) {{{ */
-const char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin)
+/* char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) {{{ */
+char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin)
 {
 	GaimBuddy *buddy;
 	gchar *str_uin;
@@ -93,7 +93,7 @@
 	buddy = gaim_find_buddy(gaim_connection_get_account(gc), str_uin);
 	if (buddy != NULL) {
 		g_free(str_uin);
-		return gaim_buddy_get_alias(buddy);
+		return g_strdup(gaim_buddy_get_alias(buddy));
 	} else {
 		return str_uin;
 	}
--- a/src/protocols/gg/utils.h	Tue Dec 06 19:22:13 2005 +0000
+++ b/src/protocols/gg/utils.h	Tue Dec 06 19:50:47 2005 +0000
@@ -78,7 +78,7 @@
  *
  * @return Name of the buddy, or UIN converted to string.
  */
-const char *
+char *
 ggp_buddy_get_name(GaimConnection *gc, const uin_t uin);
 
 #endif /* _GAIM_GG_UTILS_H */