[nautilus/1759-crash-closing-last-tab: 13/13] window: Handle NULL active_slot pointer




commit e771411670e304dee6288e9278b6bf98da561014
Author: António Fernandes <antoniof gnome org>
Date:   Sat Feb 27 15:49:05 2021 +0000

    window: Handle NULL active_slot pointer
    
    This pointer may be NULL. Usually this may happen only during window
    initialization and destruction. However, for robustness, make sure
    every use either handles a NULL pointer or asserts it's non-NULL.

 src/nautilus-window.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index e4294f6dd..53a4fa527 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1434,7 +1434,7 @@ nautilus_window_slot_close (NautilusWindow     *window,
     NautilusNavigationState *data;
 
     DEBUG ("Requesting to remove slot %p from window %p", slot, window);
-    if (window == NULL)
+    if (window == NULL || slot == NULL)
     {
         return;
     }
@@ -1465,7 +1465,7 @@ nautilus_window_sync_bookmarks (NautilusWindow *window)
     GFile *location;
 
     slot = window->active_slot;
-    location = nautilus_window_slot_get_location (slot);
+    location = slot != NULL ? nautilus_window_slot_get_location (slot) : NULL;
 
     if (location != NULL)
     {
@@ -1487,6 +1487,9 @@ nautilus_window_sync_location_widgets (NautilusWindow *window)
     gboolean enabled;
 
     slot = window->active_slot;
+    /* This function is called by the active slot. */
+    g_assert (slot != NULL);
+
     location = nautilus_window_slot_get_location (slot);
 
     /* Change the location bar and path bar to match the current location. */
@@ -1766,6 +1769,11 @@ nautilus_window_show_operation_notification (NautilusWindow *window,
     NautilusFile *folder;
     GFile *current_location;
 
+    if (window->active_slot == NULL)
+    {
+        return;
+    }
+
     current_location = nautilus_window_slot_get_location (window->active_slot);
     if (gtk_window_has_toplevel_focus (GTK_WINDOW (window)))
     {
@@ -2520,7 +2528,8 @@ nautilus_window_key_press_event (GtkWidget   *widget,
         return GDK_EVENT_STOP;
     }
 
-    if (nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event))
+    if (window->active_slot != NULL &&
+        nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event))
     {
         return GDK_EVENT_STOP;
     }


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