[nautilus/wip/oholy/g-object-bind-property-crashes] window-slot: Prevent crashes caused by invalid pointers



commit 35f4e16a85e8d5fe7a8352e5d34642dee64f4ae2
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Feb 26 09:13:25 2020 +0100

    window-slot: Prevent crashes caused by invalid pointers
    
    Nautilus randomly crashes when g_object_bind_property is used to bind
    extensions-background-menu and templates-menu properties of
    NautilusFilesView and NautilusWindowSlot. Although, we don't have any
    reproducer, it seems that this is because NautilusWindowSlot uses
    g_object_ref when storing the property, but not g_object_unref, and
    NautilusFilesView does the opposite. It seems that NautilusFilesView
    can hold invalid references in certain cases because of that. The
    both objects should hold its own references to prevent this. Let's
    replace the custom codes by g_set_object to achive this behavior.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/issues/813

 src/nautilus-files-view.c  | 6 ++----
 src/nautilus-window-slot.c | 4 ++--
 2 files changed, 4 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 427ac08c5..5573701cc 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -776,8 +776,7 @@ real_set_extensions_background_menu (NautilusView *view,
 
     priv = nautilus_files_view_get_instance_private (NAUTILUS_FILES_VIEW (view));
 
-    g_clear_object (&priv->extensions_background_menu);
-    priv->extensions_background_menu = menu;
+    g_set_object (&priv->extensions_background_menu, menu);
 }
 
 static void
@@ -790,8 +789,7 @@ real_set_templates_menu (NautilusView *view,
 
     priv = nautilus_files_view_get_instance_private (NAUTILUS_FILES_VIEW (view));
 
-    g_clear_object (&priv->templates_menu);
-    priv->templates_menu = menu;
+    g_set_object (&priv->templates_menu, menu);
 }
 
 static gboolean
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index ee15f4c68..7fe24f09c 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -769,7 +769,7 @@ real_set_extensions_background_menu (NautilusWindowSlot *self,
     NautilusWindowSlotPrivate *priv;
     priv = nautilus_window_slot_get_instance_private (self);
 
-    priv->extensions_background_menu = menu != NULL ? g_object_ref (menu) : NULL;
+    g_set_object (&priv->extensions_background_menu, menu);
 }
 
 static void
@@ -779,7 +779,7 @@ real_set_templates_menu (NautilusWindowSlot *self,
     NautilusWindowSlotPrivate *priv;
     priv = nautilus_window_slot_get_instance_private (self);
 
-    priv->templates_menu = menu != NULL ? g_object_ref (menu) : NULL;
+    g_set_object (&priv->templates_menu, menu);
 }
 
 static void


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