[gtk/wip/chergert/fix-menutracker: 1/2] menutrackeritem: be defensive during finalize




commit f9c0fc4fddc6209efdad838cff0bb457084a1e81
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 24 13:50:08 2022 -0700

    menutrackeritem: be defensive during finalize
    
    The menu/action system tends to be incredibly re-entrant, and while fixing
    the misuse during finalization cycles should be a priority, this can help
    protect just a bit more.
    
    Related #5009

 gtk/gtkmenutrackeritem.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
index cccfb48a85..11db1f4abb 100644
--- a/gtk/gtkmenutrackeritem.c
+++ b/gtk/gtkmenutrackeritem.c
@@ -201,13 +201,10 @@ gtk_menu_tracker_item_finalize (GObject *object)
 {
   GtkMenuTrackerItem *self = GTK_MENU_TRACKER_ITEM (object);
 
-  g_free (self->action_namespace);
-  g_free (self->action_and_target);
-
-  if (self->observable)
-    g_object_unref (self->observable);
-
-  g_object_unref (self->item);
+  g_clear_pointer (&self->action_namespace, g_free);
+  g_clear_pointer (&self->action_and_target, g_free);
+  g_clear_object (&self->observable);
+  g_clear_object (&self->item);
 
   G_OBJECT_CLASS (gtk_menu_tracker_item_parent_class)->finalize (object);
 }
@@ -884,7 +881,7 @@ gtk_menu_tracker_opener_finalize (GObject *object)
 
   gtk_menu_tracker_item_set_submenu_shown (opener->item, FALSE);
 
-  g_free (opener->submenu_action);
+  g_clear_pointer (&opener->submenu_action, g_free);
 
   G_OBJECT_CLASS (gtk_menu_tracker_opener_parent_class)->finalize (object);
 }


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