[gtk+] Fixed GtkToolPalette ->forall implementation to be gtk_widget_destroy friendly



commit a37976dae05b6a7833b77025568848f329d67af8
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Tue Feb 1 04:57:05 2011 +0900

    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 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtktoolpalette.c b/gtk/gtktoolpalette.c
index fea7bf1..fa5188c 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);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]