Fix file chooser refcounting issues

This was reported in bug 600992.
This commit is contained in:
Matthias Clasen 2010-03-08 23:56:43 -05:00
parent 2036d9262e
commit bf88eee131
5 changed files with 53 additions and 19 deletions

View File

@ -1586,7 +1586,7 @@ model_free_row_data (GtkFileChooserButton *button,
g_object_unref (data); g_object_unref (data);
break; break;
case ROW_TYPE_VOLUME: case ROW_TYPE_VOLUME:
_gtk_file_system_volume_free (data); _gtk_file_system_volume_unref (data);
break; break;
default: default:
break; break;
@ -1777,11 +1777,16 @@ model_add_volumes (GtkFileChooserButton *button,
GFile *base_file; GFile *base_file;
base_file = _gtk_file_system_volume_get_root (volume); base_file = _gtk_file_system_volume_get_root (volume);
if (base_file != NULL && !g_file_is_native (base_file)) if (base_file != NULL)
{ {
_gtk_file_system_volume_free (volume); if (!g_file_is_native (base_file))
continue; {
} g_object_unref (base_file);
continue;
}
else
g_object_unref (base_file);
}
} }
} }
@ -1796,7 +1801,7 @@ model_add_volumes (GtkFileChooserButton *button,
ICON_COLUMN, pixbuf, ICON_COLUMN, pixbuf,
DISPLAY_NAME_COLUMN, display_name, DISPLAY_NAME_COLUMN, display_name,
TYPE_COLUMN, ROW_TYPE_VOLUME, TYPE_COLUMN, ROW_TYPE_VOLUME,
DATA_COLUMN, volume, DATA_COLUMN, _gtk_file_system_volume_ref (volume),
IS_FOLDER_COLUMN, TRUE, IS_FOLDER_COLUMN, TRUE,
-1); -1);
@ -2334,7 +2339,7 @@ update_label_and_image (GtkFileChooserButton *button)
if (base_file) if (base_file)
g_object_unref (base_file); g_object_unref (base_file);
_gtk_file_system_volume_free (volume); _gtk_file_system_volume_unref (volume);
if (label_text) if (label_text)
goto out; goto out;

View File

@ -762,14 +762,12 @@ shortcuts_free_row_data (GtkFileChooserDefault *impl,
GtkFileSystemVolume *volume; GtkFileSystemVolume *volume;
volume = col_data; volume = col_data;
_gtk_file_system_volume_free (volume); _gtk_file_system_volume_unref (volume);
} }
else if (shortcut_type == SHORTCUT_TYPE_FILE)
{ {
GFile *file; GFile *file;
g_assert (shortcut_type == SHORTCUT_TYPE_FILE);
file = col_data; file = col_data;
g_object_unref (file); g_object_unref (file);
} }
@ -2015,7 +2013,14 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
} }
} }
shortcuts_insert_file (impl, start_row + n, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_VOLUMES); shortcuts_insert_file (impl,
start_row + n,
SHORTCUT_TYPE_VOLUME,
_gtk_file_system_volume_ref (volume),
NULL,
NULL,
FALSE,
SHORTCUTS_VOLUMES);
n++; n++;
} }
@ -3437,9 +3442,7 @@ shortcuts_query_tooltip_cb (GtkWidget *widget,
if (shortcut_type == SHORTCUT_TYPE_SEPARATOR) if (shortcut_type == SHORTCUT_TYPE_SEPARATOR)
return FALSE; return FALSE;
else if (shortcut_type == SHORTCUT_TYPE_VOLUME) else if (shortcut_type == SHORTCUT_TYPE_VOLUME)
{ return FALSE;
return FALSE;
}
else if (shortcut_type == SHORTCUT_TYPE_FILE) else if (shortcut_type == SHORTCUT_TYPE_FILE)
{ {
GFile *file; GFile *file;
@ -9770,6 +9773,9 @@ shortcuts_activate_mount_enclosing_volume (GCancellable *cancellable,
_gtk_file_system_get_info (data->impl->file_system, data->file, _gtk_file_system_get_info (data->impl->file_system, data->file,
"standard::type", "standard::type",
shortcuts_activate_get_info_cb, data); shortcuts_activate_get_info_cb, data);
if (volume)
_gtk_file_system_volume_unref (volume);
} }
static void static void

View File

@ -468,6 +468,8 @@ get_volumes_list (GtkFileSystem *file_system)
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (drive)); priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (drive));
} }
g_object_unref (drive);
} }
g_list_free (drives); g_list_free (drives);
@ -499,6 +501,8 @@ get_volumes_list (GtkFileSystem *file_system)
/* see comment above in why we add an icon for a volume */ /* see comment above in why we add an icon for a volume */
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (volume)); priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (volume));
} }
g_object_unref (volume);
} }
/* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */ /* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */
@ -520,11 +524,13 @@ get_volumes_list (GtkFileSystem *file_system)
*/ */
if (mount_referenced_by_volume_activation_root (volumes, mount)) if (mount_referenced_by_volume_activation_root (volumes, mount))
{ {
g_object_unref (mount);
continue; continue;
} }
/* show this mount */ /* show this mount */
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (mount)); priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (mount));
g_object_unref (mount);
} }
g_list_free (volumes); g_list_free (volumes);
@ -1025,6 +1031,8 @@ enclosing_volume_mount_cb (GObject *source_object,
if (error) if (error)
g_error_free (error); g_error_free (error);
_gtk_file_system_volume_unref (volume);
} }
GCancellable * GCancellable *
@ -1802,8 +1810,22 @@ _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
return pixbuf; return pixbuf;
} }
GtkFileSystemVolume *
_gtk_file_system_volume_ref (GtkFileSystemVolume *volume)
{
if (IS_ROOT_VOLUME (volume))
return volume;
if (G_IS_MOUNT (volume) ||
G_IS_VOLUME (volume) ||
G_IS_DRIVE (volume))
g_object_ref (volume);
return volume;
}
void void
_gtk_file_system_volume_free (GtkFileSystemVolume *volume) _gtk_file_system_volume_unref (GtkFileSystemVolume *volume)
{ {
/* Root volume doesn't need to be freed */ /* Root volume doesn't need to be freed */
if (IS_ROOT_VOLUME (volume)) if (IS_ROOT_VOLUME (volume))

View File

@ -162,7 +162,8 @@ GdkPixbuf * _gtk_file_system_volume_render_icon (GtkFileSystemVol
gint icon_size, gint icon_size,
GError **error); GError **error);
void _gtk_file_system_volume_free (GtkFileSystemVolume *volume); GtkFileSystemVolume *_gtk_file_system_volume_ref (GtkFileSystemVolume *volume);
void _gtk_file_system_volume_unref (GtkFileSystemVolume *volume);
/* GtkFileSystemBookmark methods */ /* GtkFileSystemBookmark methods */
void _gtk_file_system_bookmark_free (GtkFileSystemBookmark *bookmark); void _gtk_file_system_bookmark_free (GtkFileSystemBookmark *bookmark);

View File

@ -1261,7 +1261,7 @@ set_button_image (GtkPathBar *path_bar,
GTK_WIDGET (path_bar), GTK_WIDGET (path_bar),
path_bar->icon_size, path_bar->icon_size,
NULL); NULL);
_gtk_file_system_volume_free (volume); _gtk_file_system_volume_unref (volume);
gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon); gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
break; break;