[nautilus/gnome-3-34] window-slot: Prevent crashes caused by invalid pointers



commit a014af15426ef3002a6744dfd97a955c83cbaac5
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Feb 26 08:13:25 2020 +0000

    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
    
    
    (cherry picked from commit 6b16de613dc87b9f84d87a46ac5987b6d7087a5c)

 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 1a1089ac6..a0a405157 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 c4d2fe1c9..3d06189f6 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]