Commit defc0cf5 authored by Matthias Clasen's avatar Matthias Clasen

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
parent f0a1a0c0
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment