diff pidgin/gtkblist.c @ 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 1bb77e24cced
children 1987beefd494
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));
 	}