[nautilus/1759-crash-closing-last-tab: 1/2] window: Add weak reference to the active slot




commit 0182308c1c85b0c9a0045ac6f74985649731e9d6
Author: António Fernandes <antoniof gnome org>
Date:   Fri Feb 5 16:14:38 2021 +0000

    window: Add weak reference to the active slot
    
    We used to explicitly set the active slot when closing a tab. However,
    we now let GtkNotebook pick the next tab, and wait for ::switch-tab to
    set the active_slot field to the one GtkNotebook picked, thanks to
    commit 475684ac9e556b144da594bf25581560d4fa5a7f.
    
    However, if the closed tab was the only tab in this window, then
    ::switch-tab is never called, so active_slot becomes a dangling
    pointer, crashing the application when trying to close the window.
    
    Use a weak reference to ensure the pointer is set to NULL in that case.
    
    Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/1759

 src/nautilus-window.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 73fe741b7..e4294f6dd 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -106,7 +106,7 @@ struct _NautilusWindow
      * Both of them may never be NULL.
      */
     GList *slots;
-    NautilusWindowSlot *active_slot;
+    NautilusWindowSlot *active_slot; /* weak reference */
 
     GtkWidget *content_paned;
 
@@ -2291,7 +2291,7 @@ nautilus_window_destroy (GtkWidget *object)
     /* the slots list should now be empty */
     g_assert (window->slots == NULL);
 
-    window->active_slot = NULL;
+    g_clear_weak_pointer (&window->active_slot);
 
     g_clear_signal_handler (&window->bookmarks_id, nautilus_application_get_bookmarks (application));
 
@@ -2447,7 +2447,7 @@ nautilus_window_set_active_slot (NautilusWindow     *window,
         nautilus_toolbar_set_window_slot (NAUTILUS_TOOLBAR (window->toolbar), NULL);
     }
 
-    window->active_slot = new_slot;
+    g_set_weak_pointer (&window->active_slot, new_slot);
 
     /* make new slot active, if it exists */
     if (new_slot)


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