[gtk/wip/chergert/fix-critical-notebook-label] notebook: fix gtk_widget_unparent() with NULL child



commit bdd7b6ec26e64abeb7f893d445e7fb2daec671c5
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 4 12:41:23 2019 -0700

    notebook: fix gtk_widget_unparent() with NULL child
    
    When using gtk4-demo and closing the window (after changing notebook tabs),
    a CRITICAL like the following is presented.
    
      gtk_widget_unparent: assertion 'GTK_IS_WIDGET (widget)' failed
    
    This fixes that by conditionally checking that we have a valid widget still
    within the GtkBin.

 gtk/gtknotebook.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 2082a1038a..2c6d03310f 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -5674,8 +5674,13 @@ static void
 gtk_notebook_menu_label_unparent (GtkWidget *widget,
                                   gpointer  data)
 {
-  gtk_widget_unparent (gtk_bin_get_child (GTK_BIN (widget)));
-  _gtk_bin_set_child (GTK_BIN (widget), NULL);
+  GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
+
+  if (child != NULL)
+    {
+      gtk_widget_unparent (child);
+      _gtk_bin_set_child (GTK_BIN (widget), NULL);
+    }
 }
 
 /* Public GtkNotebook Page Insert/Remove Methods :


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