summaryrefslogtreecommitdiff
path: root/gtk/gtktoolpalette.c
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2011-02-01 04:57:05 +0900
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2011-02-01 05:02:56 +0900
commita37976dae05b6a7833b77025568848f329d67af8 (patch)
treea8289512d42fb304d3b9baf2943a5b059c32bf90 /gtk/gtktoolpalette.c
parentddb4b3ebe2fca5eb5da6bc6a70549885df10faaf (diff)
downloadgtk+-a37976dae05b6a7833b77025568848f329d67af8.tar.gz
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).
Diffstat (limited to 'gtk/gtktoolpalette.c')
-rw-r--r--gtk/gtktoolpalette.c10
1 files 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);
}
}