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




commit fa3a4dfa16700d3ad1a94ca3ed552cbb4af3e72c
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 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 73fe741b7..b542ac2d8 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -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]