changeset 18646:05cab350d1fb

Fix memory leak by freeing the list returned by gtk_container_get_children.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 27 Jul 2007 10:44:11 +0000
parents 9e55f853a6fa
children a5f441181e48
files pidgin/gtkblist.c pidgin/gtkconv.c
diffstat 2 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkblist.c	Wed Jul 25 21:01:29 2007 +0000
+++ b/pidgin/gtkblist.c	Fri Jul 27 10:44:11 2007 +0000
@@ -629,8 +629,7 @@
 
 	gc = purple_account_get_connection(data->account);
 
-	while ((tmp = gtk_container_get_children(GTK_CONTAINER(data->entries_box))))
-		gtk_widget_destroy(tmp->data);
+	gtk_container_foreach(GTK_CONTAINER(data->entries_box), (GtkCallback)gtk_widget_destroy, NULL);
 
 	g_list_free(data->entries);
 	data->entries = NULL;
@@ -4000,6 +3999,7 @@
 	char *primary;
 	const char *text;
 	gboolean enabled;
+	GList *list;
 
 	account = user_data;
 	primary = g_strdup_printf(_("%s disconnected"),
@@ -4018,8 +4018,10 @@
 	g_free(primary);
 	gtk_widget_destroy(GTK_WIDGET(widget));
 	g_hash_table_remove(gtkblist->connection_errors, account);
-	if (gtk_container_get_children(GTK_CONTAINER(gtkblist->error_buttons)) == NULL) {
+	if ((list = gtk_container_get_children(GTK_CONTAINER(gtkblist->error_buttons))) == NULL) {
 		gtk_widget_hide(gtkblist->error_buttons);
+	} else {
+		g_list_free(list);
 	}
 }
 
@@ -4089,7 +4091,7 @@
 	/* Remove the old error buttons */
 	for (l = gtk_container_get_children(GTK_CONTAINER(gtkblist->error_buttons));
 			l != NULL;
-			l = l->next)
+			l = g_list_delete_link(l, l))
 	{
 		gtk_widget_destroy(GTK_WIDGET(l->data));
 	}
@@ -5648,8 +5650,7 @@
 
 	gc = purple_account_get_connection(data->account);
 
-	while ((tmp = gtk_container_get_children(GTK_CONTAINER(data->entries_box))))
-		gtk_widget_destroy(tmp->data);
+	gtk_container_foreach(GTK_CONTAINER(data->entries_box), (GtkCallback)gtk_widget_destroy, NULL);
 
 	g_list_free(data->entries);
 
@@ -6526,7 +6527,7 @@
 		return;
 
 	/* Clear the old Accounts menu */
-	for (l = gtk_container_get_children(GTK_CONTAINER(accountmenu)); l; l = l->next) {
+	for (l = gtk_container_get_children(GTK_CONTAINER(accountmenu)); l; l = g_list_delete_link(l, l)) {
 		menuitem = l->data;
 
 		if (menuitem != gtk_item_factory_get_widget(gtkblist->ift, N_("/Accounts/Add\\/Edit")))
@@ -6737,7 +6738,7 @@
 		return;
 
 	/* Clear the old menu */
-	for (l = gtk_container_get_children(GTK_CONTAINER(sortmenu)); l; l = l->next) {
+	for (l = gtk_container_get_children(GTK_CONTAINER(sortmenu)); l; l = g_list_delete_link(l, l)) {
 		menuitem = l->data;
 		gtk_widget_destroy(GTK_WIDGET(menuitem));
 	}
--- a/pidgin/gtkconv.c	Wed Jul 25 21:01:29 2007 +0000
+++ b/pidgin/gtkconv.c	Fri Jul 27 10:44:11 2007 +0000
@@ -2975,7 +2975,7 @@
 	for (list = gtk_container_get_children(GTK_CONTAINER(menu)); list; )
 	{
 		GtkWidget *w = list->data;
-		list = list->next;
+		list = g_list_delete_link(list, list);
 		gtk_widget_destroy(w);
 	}
 
@@ -2993,6 +2993,10 @@
 		gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 		gtk_widget_set_sensitive(item, FALSE);
 	}
+	else
+	{
+		g_list_free(list);
+	}
 
 	gtk_widget_show_all(menu);
 }
@@ -3373,7 +3377,7 @@
 
 	for (child = gtk_container_get_children(GTK_CONTAINER(menu));
 		 child != NULL;
-		 child = child->next) {
+		 child = g_list_delete_link(child, child)) {
 
 		GtkWidget *item = child->data;
 		PurpleBuddy *item_buddy;