filebrowser: Don't leak GFiles

e2f792359a
This commit is contained in:
JosephMcc 2017-02-13 15:57:16 -08:00
parent fe9e6ac91c
commit fa31c65c2f
5 changed files with 116 additions and 67 deletions

View File

@ -323,37 +323,36 @@ set_item_message (WindowData *data,
XedFileBrowserStore *store;
GFile *location;
guint flags = 0;
gchar *track_id;
store = xed_file_browser_widget_get_browser_store (data->widget);
gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1);
if (!location)
if (location)
{
return;
}
gchar *track_id;
if (path && gtk_tree_path_get_depth (path) != 0)
{
track_id = track_row (data, store, path, location);
}
else
{
track_id = NULL;
}
if (path && gtk_tree_path_get_depth (path) != 0)
{
track_id = track_row (data, store, path, location);
}
else
{
track_id = NULL;
}
xed_message_set (message, "id", track_id, "location", location, NULL);
xed_message_set (message, "id", track_id, "location", location, NULL);
if (xed_message_has_key (message, "is_directory"))
{
xed_message_set (message, "is_directory", FILE_IS_DIR (flags), NULL);
if (xed_message_has_key (message, "is_directory"))
{
xed_message_set (message, "is_directory", FILE_IS_DIR (flags), NULL);
}
g_free (track_id);
g_object_unref (location);
}
g_free (track_id);
}
static gboolean
@ -387,6 +386,8 @@ custom_message_filter_func (XedFileBrowserWidget *widget,
xed_message_bus_send_message_sync (wdata->bus, data->message);
xed_message_get (data->message, "filter", &filter, NULL);
g_object_unref (location);
return !filter;
}

View File

@ -349,9 +349,6 @@ on_action_open_terminal (GtkAction *action,
XedFileBrowserPlugin *plugin)
{
XedFileBrowserPluginPrivate *priv = plugin->priv;
gchar *terminal;
gchar *local;
gchar *argv[2];
GFile *file;
GtkTreeIter iter;
@ -366,29 +363,32 @@ on_action_open_terminal (GtkAction *action,
store = xed_file_browser_widget_get_browser_store (priv->tree_widget);
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &file, -1);
if (file == NULL)
if (file)
{
return;
gchar *terminal;
gchar *local;
gchar *argv[2];
terminal = get_terminal (plugin);
local = g_file_get_path (file);
argv[0] = terminal;
argv[1] = NULL;
g_spawn_async (local,
argv,
NULL,
G_SPAWN_SEARCH_PATH,
NULL,
NULL,
NULL,
NULL);
g_free (terminal);
g_free (local);
g_object_unref (file);
}
terminal = get_terminal (plugin);
local = g_file_get_path (file);
argv[0] = terminal;
argv[1] = NULL;
g_spawn_async (local,
argv,
NULL,
G_SPAWN_SEARCH_PATH,
NULL,
NULL,
NULL,
NULL);
g_free (terminal);
g_free (local);
}
static void
@ -400,7 +400,6 @@ on_selection_changed_cb (GtkTreeSelection *selection,
GtkTreeModel *model;
GtkTreeIter iter;
gboolean sensitive;
GFile *location;
tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (priv->tree_widget));
model = gtk_tree_view_get_model (tree_view);
@ -414,9 +413,19 @@ on_selection_changed_cb (GtkTreeSelection *selection,
if (sensitive)
{
GFile *location;
gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
sensitive = g_file_has_uri_scheme (location, "file");
if (location)
{
sensitive = g_file_has_uri_scheme (location, "file");
g_object_unref (location);
}
else
{
sensitive = FALSE;
}
}
gtk_action_set_sensitive (gtk_action_group_get_action (priv->single_selection_action_group, "OpenTerminal"), sensitive);
@ -927,11 +936,18 @@ get_filename_from_path (GtkTreeModel *model,
{
GtkTreeIter iter;
GFile *location;
gchar *ret = NULL;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
return xed_file_browser_utils_file_basename (location);
if (location)
{
ret = xed_file_browser_utils_file_basename (location);
g_object_unref (location);
}
return ret;
}
static gboolean

View File

@ -1027,6 +1027,7 @@ xed_file_browser_store_drag_data_get (GtkTreeDragSource *drag_source,
ret = gtk_selection_data_set_uris (selection_data, uris);
g_free (uris[0]);
g_object_unref (location);
return ret;
}

View File

@ -165,7 +165,6 @@ row_expanded (GtkTreeView *tree_view,
GtkTreePath *path)
{
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view);
GFile *location;
if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded)
{
@ -179,9 +178,16 @@ row_expanded (GtkTreeView *tree_view,
if (view->priv->restore_expand_state)
{
GFile *location;
gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
add_expand_state (view, location);
if (location)
{
g_object_unref (location);
}
}
_xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), iter);
@ -193,7 +199,6 @@ row_collapsed (GtkTreeView *tree_view,
GtkTreePath *path)
{
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view);
GFile *location;
if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed)
{
@ -207,9 +212,16 @@ row_collapsed (GtkTreeView *tree_view,
if (view->priv->restore_expand_state)
{
GFile *location;
gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
remove_expand_state (view, location);
if (location)
{
g_object_unref (location);
}
}
_xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), iter);
@ -747,7 +759,6 @@ fill_expand_state (XedFileBrowserView *view,
{
GtkTreePath * path;
GtkTreeIter child;
GFile *location;
if (!gtk_tree_model_iter_has_child (view->priv->model, iter))
{
@ -758,6 +769,8 @@ fill_expand_state (XedFileBrowserView *view,
if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path))
{
GFile *location;
gtk_tree_model_get (view->priv->model,
iter,
XED_FILE_BROWSER_STORE_COLUMN_LOCATION,
@ -765,6 +778,11 @@ fill_expand_state (XedFileBrowserView *view,
-1);
add_expand_state (view, location);
if (location)
{
g_object_unref (location);
}
}
if (gtk_tree_model_iter_children (view->priv->model, &child, iter))
@ -1269,7 +1287,6 @@ restore_expand_state (XedFileBrowserView *view,
GtkTreeIter *iter)
{
GFile *location;
GtkTreePath *path;
gtk_tree_model_get (GTK_TREE_MODEL (model),
iter,
@ -1277,19 +1294,20 @@ restore_expand_state (XedFileBrowserView *view,
&location,
-1);
if (!location)
if (location)
{
return;
GtkTreePath *path;
path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
if (g_hash_table_lookup (view->priv->expand_state, location))
{
gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE);
}
gtk_tree_path_free (path);
g_object_unref (location);
}
path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
if (g_hash_table_lookup (view->priv->expand_state, location))
{
gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE);
}
gtk_tree_path_free (path);
}
static void

View File

@ -2493,6 +2493,11 @@ file_open (XedFileBrowserWidget *obj,
{
g_signal_emit (obj, signals[LOCATION_ACTIVATED], 0, location);
}
if (location)
{
g_object_unref (location);
}
}
static gboolean
@ -2526,6 +2531,7 @@ directory_open (XedFileBrowserWidget *obj,
}
g_free (uri);
g_object_unref (location);
}
return result;
@ -2577,11 +2583,6 @@ on_virtual_root_changed (XedFileBrowserStore *model,
XedFileBrowserWidget *obj)
{
GtkTreeIter iter;
GFile *location;
GtkTreeIter root;
GtkAction *action;
Location *loc;
GdkPixbuf *pixbuf;
if (gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)) != GTK_TREE_MODEL (obj->priv->file_store))
{
@ -2590,12 +2591,20 @@ on_virtual_root_changed (XedFileBrowserStore *model,
if (xed_file_browser_store_get_iter_virtual_root (model, &iter))
{
GFile *location;
GtkTreeIter root;
gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
if (xed_file_browser_store_get_iter_root (model, &root))
{
GtkAction *action;
if (!obj->priv->changing_location)
{
Location *loc;
GdkPixbuf *pixbuf;
/* Remove all items from obj->priv->current_location on */
if (obj->priv->current_location)
{
@ -2632,7 +2641,6 @@ on_virtual_root_changed (XedFileBrowserStore *model,
{
g_object_unref (pixbuf);
}
}
action = gtk_action_group_get_action (obj->priv->action_group, "DirectoryUp");
@ -2650,6 +2658,11 @@ on_virtual_root_changed (XedFileBrowserStore *model,
}
check_current_item (obj, TRUE);
if (location)
{
g_object_unref (location);
}
}
else
{