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




commit 8f5f2d8ed6ba3146988c7b95ec77f82b9bd27cca
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 047d3b4b8..532c21e37 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -4450,6 +4450,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;
     }
@@ -4527,6 +4528,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]