From a37976dae05b6a7833b77025568848f329d67af8 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Tue, 1 Feb 2011 04:57:05 +0900 Subject: [PATCH] Fixed GtkToolPalette ->forall implementation to be gtk_widget_destroy friendly The forall() loop was buggy as it was skipping items in the list when the current item gets removed from the groups array as a result of calling the callback (causing memory leaks). --- gtk/gtktoolpalette.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gtk/gtktoolpalette.c b/gtk/gtktoolpalette.c index fea7bf1f5c..fa5188cde0 100644 --- a/gtk/gtktoolpalette.c +++ b/gtk/gtktoolpalette.c @@ -831,15 +831,21 @@ gtk_tool_palette_forall (GtkContainer *container, gpointer callback_data) { GtkToolPalette *palette = GTK_TOOL_PALETTE (container); - guint i; - + guint i, len; for (i = 0; i < palette->priv->groups->len; ++i) { GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i); + + len = palette->priv->groups->len; + if (info->widget) callback (GTK_WIDGET (info->widget), callback_data); + + /* At destroy time, 'callback' results in removing a widget, + * here we just reset the current index to account for the removed widget. */ + i -= (len - palette->priv->groups->len); } }