[nautilus/wip/apoos-maximus/gsoc2020] properties-window: Clear list of dangling pointers



commit 5f9d85e1d050d1ff5769a13c6e9cc46b9836ec21
Author: António Fernandes <antoniof gnome org>
Date:   Sat Jul 4 21:51:53 2020 +0100

    properties-window: Clear list of dangling pointers
    
    The window->change_permission_combos list is populated each time the
    "Change Permissions of Enclosed Files" button is clicked.
    
    This list is cleared when the Properties window is destroyed, but
    not when the "Change Permissions of Enclosed Files" dialog is. As a
    result, if the button is clicked again, new combos are prepended to
    the list but the previous (now-dangling) pointers are still there.
    
    If GLib is built without -DG_DISABLE_CAST_CHECKS, then trying to use
    this dialog a second time to change permissions of enclosed files will
    result in a crash due to the dangling pointers failing a cast check.
    But even though production code will not crash this way, leaving
    dangling pointers in the list is a bad idea.
    
    Before this dialog was ported to a GtkBuilder UI definition, this bug
    was masked by a leak of floating references.
    
    To properly manage the lifecycle of this list, let's clear it whenever
    the dialog is destroyed.

 src/nautilus-properties-window.c | 2 ++
 1 file changed, 2 insertions(+)
---
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index b2bf3ed67..348f09f46 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -4441,6 +4441,7 @@ on_change_permissions_response (GtkDialog                *dialog,
 
     if (response != GTK_RESPONSE_OK)
     {
+        g_clear_pointer (&window->change_permission_combos, g_list_free);
         gtk_widget_destroy (GTK_WIDGET (dialog));
         return;
     }
@@ -4518,6 +4519,7 @@ on_change_permissions_response (GtkDialog                *dialog,
             g_free (uri);
         }
     }
+    g_clear_pointer (&window->change_permission_combos, g_list_free);
     gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 


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