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
This commit is contained in:
Matthias Clasen 2015-08-06 14:51:25 +02:00
parent f0a1a0c0a4
commit defc0cf5df

View File

@ -1580,8 +1580,7 @@ out:
gtk_tree_row_reference_free (data->row_ref); gtk_tree_row_reference_free (data->row_ref);
g_free (data); g_free (data);
if (model_cancellable) g_object_unref (cancellable);
g_object_unref (model_cancellable);
} }
static void static void
@ -1684,10 +1683,7 @@ model_free_row_data (GtkFileChooserButton *button,
-1); -1);
if (cancellable) if (cancellable)
{ g_cancellable_cancel (cancellable);
g_cancellable_cancel (cancellable);
g_object_unref (cancellable);
}
switch (type) switch (type)
{ {
@ -1767,8 +1763,7 @@ out:
gtk_tree_row_reference_free (data->row_ref); gtk_tree_row_reference_free (data->row_ref);
g_free (data); g_free (data);
if (model_cancellable) g_object_unref (cancellable);
g_object_unref (model_cancellable);
} }
static void 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 the combo box popup got dismissed, go back to showing the ROW_TYPE_EMPTY_SELECTION if needed */
if (!popup_shown) if (!popup_shown)
{ {
GFile *selected = get_selected_file (button); GFile *selected = get_selected_file (button);