[gnome-builder] libide/core: be more careful with settings destroy callback



commit 431f0aadbe5435313724f156100055643fd800d3
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 18 17:20:12 2022 -0700

    libide/core: be more careful with settings destroy callback

 src/libide/core/ide-layered-settings.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/src/libide/core/ide-layered-settings.c b/src/libide/core/ide-layered-settings.c
index 8ac770d31..6424ae775 100644
--- a/src/libide/core/ide-layered-settings.c
+++ b/src/libide/core/ide-layered-settings.c
@@ -477,6 +477,8 @@ ide_layered_settings_bind_with_mapping (IdeLayeredSettings      *self,
                                         GDestroyNotify           destroy)
 {
   static const GSettingsBindFlags default_flags = G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET;
+  GDestroyNotify get_destroy = destroy;
+  GDestroyNotify set_destroy = destroy;
 
   g_return_if_fail (IDE_IS_LAYERED_SETTINGS (self));
   g_return_if_fail (key != NULL);
@@ -487,6 +489,14 @@ ide_layered_settings_bind_with_mapping (IdeLayeredSettings      *self,
   if ((flags & default_flags) == 0)
     flags |= default_flags;
 
+  /* Ensure @destroy is only called once, on the longer living
+   * setting binding (potential for longer living that is).
+   */
+  if ((flags & G_SETTINGS_BIND_SET) != 0)
+    get_destroy = NULL;
+  else
+    set_destroy = NULL;
+
   /*
    * Our memory backend/settings are compiling the values from all of the
    * layers. Therefore, we only want to map reads from the memory backend. We
@@ -495,13 +505,13 @@ ide_layered_settings_bind_with_mapping (IdeLayeredSettings      *self,
   if ((flags & G_SETTINGS_BIND_GET) != 0)
     g_settings_bind_with_mapping (self->memory_settings, key, object, property,
                                   (flags & ~G_SETTINGS_BIND_SET),
-                                  get_mapping, set_mapping, user_data, destroy);
+                                  get_mapping, NULL, user_data, get_destroy);
 
-  /* We bind writability directly to our toplevel layer */
+  /* We bind writability directly to our toplevel layer. */
   if ((flags & G_SETTINGS_BIND_SET) != 0)
     g_settings_bind_with_mapping (ide_layered_settings_get_primary_settings (self),
                                   key, object, property, (flags & ~G_SETTINGS_BIND_GET),
-                                  get_mapping, set_mapping, user_data, destroy);
+                                  NULL, set_mapping, user_data, set_destroy);
 
   /* Get initial value in case our memory settings doesn't have it */
   if ((flags & G_SETTINGS_BIND_GET) != 0)


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