diff --git a/thunar/thunar-dnd.c b/thunar/thunar-dnd.c index 9871eb0..a1ff0e8 100644 --- a/thunar/thunar-dnd.c +++ b/thunar/thunar-dnd.c @@ -180,7 +180,7 @@ thunar_dnd_ask (GtkWidget *widget, /* cleanup */ g_object_unref (G_OBJECT (factory)); - g_list_free (file_list); + g_list_free_full (file_list, g_object_unref); return dnd_action; } diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index fece42f..4d89b09 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -95,6 +95,9 @@ enum static void thunar_file_info_init (ThunarxFileInfoIface *iface); static void thunar_file_dispose (GObject *object); static void thunar_file_finalize (GObject *object); +static void thunar_file_toggle_notify (gpointer data, + GObject *object, + gboolean is_last_ref); static gchar *thunar_file_info_get_name (ThunarxFileInfo *file_info); static gchar *thunar_file_info_get_uri (ThunarxFileInfo *file_info); static gchar *thunar_file_info_get_parent_uri (ThunarxFileInfo *file_info); @@ -284,11 +287,6 @@ thunar_file_finalize (GObject *object) } #endif - /* drop the entry from the cache */ - G_LOCK (file_cache_mutex); - g_hash_table_remove (file_cache, file->gfile); - G_UNLOCK (file_cache_mutex); - /* drop a reference on the metadata if we own one */ if ((file->flags & THUNAR_FILE_OWNS_METAFILE_REFERENCE) != 0) g_object_unref (G_OBJECT (metafile)); @@ -315,6 +313,25 @@ thunar_file_finalize (GObject *object) +static void +thunar_file_toggle_notify (gpointer data, GObject *object, gboolean is_last_ref) +{ + ThunarFile *file = THUNAR_FILE (object); + + if (is_last_ref) + { + /* drop the entry from the cache */ + G_LOCK (file_cache_mutex); + g_hash_table_remove (file_cache, file->gfile); + G_UNLOCK (file_cache_mutex); + + /* remove cache reference */ + g_object_remove_toggle_ref (G_OBJECT (file), thunar_file_toggle_notify, NULL); + } +} + + + static gchar * thunar_file_info_get_name (ThunarxFileInfo *file_info) { @@ -560,6 +577,8 @@ thunar_file_monitor_update (GFile *path, default: break; } + + g_object_unref (file); } } @@ -613,12 +632,7 @@ thunar_file_get (GFile *gfile, /* check if we already have a cached version of that file */ file = thunar_file_cache_lookup (gfile); - if (G_UNLIKELY (file != NULL)) - { - /* take a reference for the caller */ - g_object_ref (file); - } - else + if (G_LIKELY (file == NULL)) { /* allocate a new object */ file = g_object_new (THUNAR_TYPE_FILE, NULL); @@ -630,6 +644,9 @@ thunar_file_get (GFile *gfile, if (thunar_file_load (file, NULL, error)) { + /* add cache reference */ + g_object_add_toggle_ref (G_OBJECT (file), thunar_file_toggle_notify, NULL); + /* insert the file into the cache */ G_LOCK (file_cache_mutex); g_hash_table_insert (file_cache, g_object_ref (file->gfile), file); @@ -1495,10 +1512,15 @@ thunar_file_accepts_drop (ThunarFile *file, && g_file_info_get_attribute_uint32 (ofile->info, G_FILE_ATTRIBUTE_UNIX_UID) != effective_user_id)) { + if (ofile != NULL) + g_object_unref (ofile); + /* default to copy and get outa here */ suggested_action = GDK_ACTION_COPY; break; } + + g_object_unref (ofile); } } } @@ -3387,7 +3409,8 @@ thunar_file_same_filesystem (const ThunarFile *file_a, * cache and returns the file present for @file in the * cache or %NULL if no #ThunarFile is cached for @file. * - * Note that no reference is taken for the caller. + * The caller is responsible to call g_object_unref() + * when done with the returned object. * * This method should not be used but in very rare cases. * Consider using thunar_file_get() instead. @@ -3415,6 +3438,9 @@ thunar_file_cache_lookup (const GFile *file) cached_file = g_hash_table_lookup (file_cache, file); + if (cached_file) + g_object_ref (cached_file); + G_UNLOCK (file_cache_mutex); return cached_file; @@ -3435,6 +3461,7 @@ thunar_file_cached_display_name (const GFile *file) { /* determine the display name of the file */ display_name = g_strdup (thunar_file_get_display_name (cached_file)); + g_object_unref (cached_file); } else { diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 2478d7e..410861e 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -2409,7 +2409,7 @@ thunar_standard_view_new_files (ThunarStandardView *standard_view, thunar_component_set_selected_files (THUNAR_COMPONENT (standard_view), file_list); /* release the file list */ - g_list_free (file_list); + g_list_free_full (file_list, g_object_unref); /* grab the focus to the view widget */ gtk_widget_grab_focus (GTK_BIN (standard_view)->child); diff --git a/thunar/thunar-thumbnailer.c b/thunar/thunar-thumbnailer.c index b902d4e..2fd941f 100644 --- a/thunar/thunar-thumbnailer.c +++ b/thunar/thunar-thumbnailer.c @@ -651,6 +651,8 @@ thunar_thumbnailer_error_idle (gpointer user_data) if (thunar_file_get_thumb_state (file) != THUNAR_FILE_THUMB_STATE_READY) thunar_file_set_thumb_state (file, THUNAR_FILE_THUMB_STATE_NONE); } + + g_object_unref (file); } /* remove the idle struct */ @@ -689,6 +691,8 @@ thunar_thumbnailer_ready_idle (gpointer user_data) /* set thumbnail state to ready - we now have a thumbnail */ thunar_file_set_thumb_state (file, THUNAR_FILE_THUMB_STATE_READY); } + + g_object_unref (file); } /* remove the idle struct */ diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c index 76d66f8..2d26da0 100644 --- a/thunar/thunar-tree-view.c +++ b/thunar/thunar-tree-view.c @@ -2173,6 +2173,9 @@ thunar_tree_view_new_files (ThunarJob *job, /* change to the newly created folder */ thunar_navigator_change_directory (THUNAR_NAVIGATOR (view), file); } + + if (file != NULL) + g_object_unref (file); } diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index d258d8f..2437671 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -2630,6 +2630,8 @@ thunar_window_mount_pre_unmount (GVolumeMonitor *volume_monitor, if (G_LIKELY (action != NULL)) gtk_action_activate (action); } + + g_object_unref (file); }