[gnome-control-center] display: Remove weak references on display disposition



commit c6da230052755afa41b428c9cfd0790ad81471a1
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Jan 31 00:35:58 2022 +0100

    display: Remove weak references on display disposition
    
    Weak references are added when logical monitors are created, however we
    don't remove them when destroying the display.
    
    This means that if a monitor survives to the display finalization
    (because may be referenced elsewhere) it will make g-c-c to crash
    during its finalization, as that will trigger the weak reference
    callback that will try to access to the already-finalized display.

 panels/display/cc-display-config-dbus.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---
diff --git a/panels/display/cc-display-config-dbus.c b/panels/display/cc-display-config-dbus.c
index bc20b6982..e896ba5a9 100644
--- a/panels/display/cc-display-config-dbus.c
+++ b/panels/display/cc-display-config-dbus.c
@@ -1665,6 +1665,25 @@ cc_display_config_dbus_get_property (GObject    *object,
     }
 }
 
+static void
+cc_display_config_dbus_dispose (GObject *object)
+{
+  CcDisplayConfigDBus *self = CC_DISPLAY_CONFIG_DBUS (object);
+
+  if (self->logical_monitors)
+    {
+      GHashTableIter iter;
+      gpointer monitor;
+
+      g_hash_table_iter_init (&iter, self->logical_monitors);
+
+      while (g_hash_table_iter_next (&iter, &monitor, NULL))
+        g_object_weak_unref (G_OBJECT (monitor), remove_logical_monitor, self);
+    }
+
+  G_OBJECT_CLASS (cc_display_config_dbus_parent_class)->dispose (object);
+}
+
 static void
 cc_display_config_dbus_finalize (GObject *object)
 {
@@ -1692,6 +1711,7 @@ cc_display_config_dbus_class_init (CcDisplayConfigDBusClass *klass)
   gobject_class->constructed = cc_display_config_dbus_constructed;
   gobject_class->set_property = cc_display_config_dbus_set_property;
   gobject_class->get_property = cc_display_config_dbus_get_property;
+  gobject_class->dispose = cc_display_config_dbus_dispose;
   gobject_class->finalize = cc_display_config_dbus_finalize;
 
   parent_class->get_monitors = cc_display_config_dbus_get_monitors;


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