[gimp/metadata-browser] app: don't rely on gtk_container_remove() to always destroy the child



commit 8b5e7715d5a49f24283e82f4c0f632ba6bac130f
Author: Michael Natterer <mitch gimp org>
Date:   Tue Feb 21 00:36:18 2012 +0100

    app: don't rely on gtk_container_remove() to always destroy the child
    
    Instead, either destroy the child instead of removing it, or remove
    *and* destroy it in cases where the remove() api on the "parent"
    doesn't match GTK+'s parent/child relation (like with all our dock
    widgets). We can't rely on remove() to implicitly detstroy, because
    there might be arbitrary other code holding references, such as
    accessibility modules and whatnot. Most likely fixes unclear crashes
    in accessibility code and other crashes we blamed GTK+ for.

 app/actions/dockable-commands.c     |   10 +++++++++-
 app/display/gimpimagewindow.c       |   27 ---------------------------
 app/tools/gimpgegltool.c            |    3 +--
 app/widgets/gimpcontainergridview.c |    5 ++---
 app/widgets/gimpcontainerpopup.c    |    3 +--
 app/widgets/gimpdock.c              |    9 ++++++++-
 app/widgets/gimpdockbook.c          |   11 +++++++++--
 app/widgets/gimpdockcolumns.c       |    9 ++++++++-
 app/widgets/gimpeditor.c            |    2 +-
 app/widgets/gimppanedbox.c          |    9 ++++++++-
 app/widgets/gimpsessioninfo-dock.c  |    4 ++++
 11 files changed, 51 insertions(+), 41 deletions(-)
---
diff --git a/app/actions/dockable-commands.c b/app/actions/dockable-commands.c
index 6fcb72d..ec1242c 100644
--- a/app/actions/dockable-commands.c
+++ b/app/actions/dockable-commands.c
@@ -62,7 +62,12 @@ dockable_close_tab_cmd_callback (GtkAction *action,
   GimpDockable *dockable = dockable_get_current (dockbook);
 
   if (dockable)
-    gimp_dockbook_remove (dockbook, dockable);
+    {
+      g_object_ref (dockable);
+      gimp_dockbook_remove (dockbook, dockable);
+      gtk_widget_destroy (GTK_WIDGET (dockable));
+      g_object_unref (dockable);
+    }
 }
 
 void
@@ -188,7 +193,10 @@ dockable_toggle_view_cmd_callback (GtkAction *action,
                       gimp_dockbook_add (dockbook, GIMP_DOCKABLE (new_dockable),
                                          page_num);
 
+                      g_object_ref (dockable);
                       gimp_dockbook_remove (dockbook, dockable);
+                      gtk_widget_destroy (GTK_WIDGET (dockable));
+                      g_object_unref (dockable);
 
                       gtk_notebook_set_current_page (GTK_NOTEBOOK (dockbook),
                                                      page_num);
diff --git a/app/display/gimpimagewindow.c b/app/display/gimpimagewindow.c
index eece01e..b8c63ba 100644
--- a/app/display/gimpimagewindow.c
+++ b/app/display/gimpimagewindow.c
@@ -426,21 +426,6 @@ gimp_image_window_constructed (GObject *object)
 }
 
 static void
-gimp_image_window_clear_docks (GimpDockColumns *columns)
-{
-  GList *docks;
-
-  do
-    {
-      docks = gimp_dock_columns_get_docks (columns);
-
-      if (docks)
-        gimp_dock_columns_remove_dock (columns, docks->data);
-    }
-  while (docks);
-}
-
-static void
 gimp_image_window_dispose (GObject *object)
 {
   GimpImageWindowPrivate *private = GIMP_IMAGE_WINDOW_GET_PRIVATE (object);
@@ -459,18 +444,6 @@ gimp_image_window_dispose (GObject *object)
       private->menubar_manager = NULL;
     }
 
-  if (private->left_docks)
-    {
-      gimp_image_window_clear_docks (GIMP_DOCK_COLUMNS (private->left_docks));
-      private->left_docks = NULL;
-    }
-
-  if (private->right_docks)
-    {
-      gimp_image_window_clear_docks (GIMP_DOCK_COLUMNS (private->right_docks));
-      private->right_docks = NULL;
-    }
-
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
diff --git a/app/tools/gimpgegltool.c b/app/tools/gimpgegltool.c
index 0e202e6..47fe532 100644
--- a/app/tools/gimpgegltool.c
+++ b/app/tools/gimpgegltool.c
@@ -679,8 +679,7 @@ gimp_gegl_tool_operation_changed (GtkWidget    *widget,
 
   if (tool->options_table)
     {
-      gtk_container_remove (GTK_CONTAINER (tool->options_frame),
-                            tool->options_table);
+      gtk_widget_destroy (tool->options_table);
       tool->options_table = NULL;
     }
 
diff --git a/app/widgets/gimpcontainergridview.c b/app/widgets/gimpcontainergridview.c
index 786eef0..88190ca 100644
--- a/app/widgets/gimpcontainergridview.c
+++ b/app/widgets/gimpcontainergridview.c
@@ -469,7 +469,7 @@ gimp_container_grid_view_remove_item (GimpContainerView *container_view,
   if (view == (GtkWidget *) grid_view->selected_item)
     grid_view->selected_item = NULL;
 
-  gtk_container_remove (GTK_CONTAINER (grid_view->wrap_box), view);
+  gtk_widget_destroy (view);
 }
 
 static void
@@ -520,8 +520,7 @@ gimp_container_grid_view_clear_items (GimpContainerView *view)
   grid_view->selected_item = NULL;
 
   while (GTK_WRAP_BOX (grid_view->wrap_box)->children)
-    gtk_container_remove (GTK_CONTAINER (grid_view->wrap_box),
-                          GTK_WRAP_BOX (grid_view->wrap_box)->children->widget);
+    gtk_widget_destroy (GTK_WRAP_BOX (grid_view->wrap_box)->children->widget);
 
   parent_view_iface->clear_items (view);
 }
diff --git a/app/widgets/gimpcontainerpopup.c b/app/widgets/gimpcontainerpopup.c
index 8e9871b..21c585a 100644
--- a/app/widgets/gimpcontainerpopup.c
+++ b/app/widgets/gimpcontainerpopup.c
@@ -499,8 +499,7 @@ gimp_container_popup_set_view_type (GimpContainerPopup *popup,
     {
       popup->view_type = view_type;
 
-      gtk_container_remove (GTK_CONTAINER (popup->frame),
-                            GTK_WIDGET (popup->editor));
+      gtk_widget_destroy (GTK_WIDGET (popup->editor));
       gimp_container_popup_create_view (popup);
     }
 }
diff --git a/app/widgets/gimpdock.c b/app/widgets/gimpdock.c
index 062e268..19adb8e 100644
--- a/app/widgets/gimpdock.c
+++ b/app/widgets/gimpdock.c
@@ -201,7 +201,14 @@ gimp_dock_dispose (GObject *object)
   GimpDock *dock = GIMP_DOCK (object);
 
   while (dock->p->dockbooks)
-    gimp_dock_remove_book (dock, GIMP_DOCKBOOK (dock->p->dockbooks->data));
+    {
+      GimpDockbook *dockbook = dock->p->dockbooks->data;
+
+      g_object_ref (dockbook);
+      gimp_dock_remove_book (dock, dockbook);
+      gtk_widget_destroy (GTK_WIDGET (dockbook));
+      g_object_unref (dockbook);
+    }
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
diff --git a/app/widgets/gimpdockbook.c b/app/widgets/gimpdockbook.c
index cbee856..bd27fcc 100644
--- a/app/widgets/gimpdockbook.c
+++ b/app/widgets/gimpdockbook.c
@@ -304,7 +304,14 @@ gimp_dockbook_dispose (GObject *object)
   gimp_dockbook_remove_tab_timeout (dockbook);
 
   while (dockbook->p->dockables)
-    gimp_dockbook_remove (dockbook, dockbook->p->dockables->data);
+    {
+      GimpDockable *dockable = dockbook->p->dockables->data;
+
+      g_object_ref (dockable);
+      gimp_dockbook_remove (dockbook, dockable);
+      gtk_widget_destroy (GTK_WIDGET (dockable));
+      g_object_unref (dockable);
+    }
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -1586,7 +1593,7 @@ static GtkIconSize
 gimp_dockbook_get_tab_icon_size (GimpDockbook *dockbook)
 {
   GtkIconSize tab_size = DEFAULT_TAB_ICON_SIZE;
-  
+
   gtk_widget_style_get (GTK_WIDGET (dockbook),
                         "tab-icon-size", &tab_size,
                         NULL);
diff --git a/app/widgets/gimpdockcolumns.c b/app/widgets/gimpdockcolumns.c
index 663b182..b28a4c1 100644
--- a/app/widgets/gimpdockcolumns.c
+++ b/app/widgets/gimpdockcolumns.c
@@ -179,7 +179,14 @@ gimp_dock_columns_dispose (GObject *object)
   GimpDockColumns *dock_columns = GIMP_DOCK_COLUMNS (object);
 
   while (dock_columns->p->docks)
-    gimp_dock_columns_remove_dock (dock_columns, dock_columns->p->docks->data);
+    {
+      GimpDock *dock = dock_columns->p->docks->data;
+
+      g_object_ref (dock);
+      gimp_dock_columns_remove_dock (dock_columns, dock);
+      gtk_widget_destroy (GTK_WIDGET (dock));
+      g_object_unref (dock);
+    }
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
diff --git a/app/widgets/gimpeditor.c b/app/widgets/gimpeditor.c
index 46e3877..2ba0fa3 100644
--- a/app/widgets/gimpeditor.c
+++ b/app/widgets/gimpeditor.c
@@ -656,7 +656,7 @@ gimp_editor_add_action_button (GimpEditor  *editor,
   old_child = gtk_bin_get_child (GTK_BIN (button));
 
   if (old_child)
-    gtk_container_remove (GTK_CONTAINER (button), old_child);
+    gtk_widget_destroy (old_child);
 
   image = gtk_image_new_from_stock (stock_id, button_icon_size);
   gtk_container_add (GTK_CONTAINER (button), image);
diff --git a/app/widgets/gimppanedbox.c b/app/widgets/gimppanedbox.c
index d04c141..de4515e 100644
--- a/app/widgets/gimppanedbox.c
+++ b/app/widgets/gimppanedbox.c
@@ -168,7 +168,14 @@ gimp_paned_box_dispose (GObject *object)
   GimpPanedBox *paned_box = GIMP_PANED_BOX (object);
 
   while (paned_box->p->widgets)
-    gimp_paned_box_remove_widget (paned_box, paned_box->p->widgets->data);
+    {
+      GtkWidget *widget = paned_box->p->widgets->data;
+
+      g_object_ref (widget);
+      gimp_paned_box_remove_widget (paned_box, widget);
+      gtk_widget_destroy (widget);
+      g_object_unref (widget);
+    }
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
diff --git a/app/widgets/gimpsessioninfo-dock.c b/app/widgets/gimpsessioninfo-dock.c
index 618276b..4f809b2 100644
--- a/app/widgets/gimpsessioninfo-dock.c
+++ b/app/widgets/gimpsessioninfo-dock.c
@@ -347,7 +347,11 @@ gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
             }
           else
             {
+              g_object_ref (dockbook);
               gimp_dock_remove_book (GIMP_DOCK (dock), GIMP_DOCKBOOK (dockbook));
+              gtk_widget_destroy (GTK_WIDGET (dockbook));
+              g_object_unref (dockbook);
+
               n_books--;
             }
 



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