[gtk+] file chooser button: Fix some refcounting confusion



commit defc0cf5df61cf556f7f0afbb9e7e4d118313cc2
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Aug 6 14:51:25 2015 +0200

    file chooser button: Fix some refcounting confusion
    
    GtkFileSystem has a complicated way to handle cancellables.
    You keep the cancellable pointer that is returned by
    _gtk_file_system_get_info and similar methods so that you can
    cancel the operation, but you do not own a reference to it.
    The only place where it is ok to unref a cancellable is in
    your callback, which gets handed a cancellable that you need
    to unref at the end. You are expected to compare it to the
    pointer you stashed away to find out if the operation has
    already been superseded by a newer call, in which case you
    disregard the results.
    
    GtkFileChooserButton was following these rules for most of
    the cancellables it keeps around, but it was sometimes unreffing
    the cancellables that are stored in the model, which could lead
    to refcount confusion and crashes. This commit makes it follow
    the rules for that case too, which fixes the crash in the bug
    below, and does not show up any leaks in valgrind under light
    testing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737804

 gtk/gtkfilechooserbutton.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index a7fb923..7a91af1 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -1580,8 +1580,7 @@ out:
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
 
-  if (model_cancellable)
-    g_object_unref (model_cancellable);
+  g_object_unref (cancellable);
 }
 
 static void
@@ -1684,10 +1683,7 @@ model_free_row_data (GtkFileChooserButton *button,
                      -1);
 
   if (cancellable)
-    {
-      g_cancellable_cancel (cancellable);
-      g_object_unref (cancellable);
-    }
+    g_cancellable_cancel (cancellable);
 
   switch (type)
     {
@@ -1767,8 +1763,7 @@ out:
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
 
-  if (model_cancellable)
-    g_object_unref (model_cancellable);
+  g_object_unref (cancellable);
 }
 
 static void
@@ -2792,6 +2787,7 @@ combo_box_notify_popup_shown_cb (GObject    *object,
 
   /* If the combo box popup got dismissed, go back to showing the ROW_TYPE_EMPTY_SELECTION if needed */
   if (!popup_shown)
+
     {
       GFile *selected = get_selected_file (button);
 


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