[Xfce4-commits] <thunar:master> Force reference on files from the cache.

Nick Schermer noreply at xfce.org
Sat May 11 15:30:01 CEST 2013


Updating branch refs/heads/master
         to 130d35acb0da0f0155e069920c6245eac091280d (commit)
       from 92dc5cb69872663e1c47c9f5990be0fce26200c4 (commit)

commit 130d35acb0da0f0155e069920c6245eac091280d
Author: Nick Schermer <nick at xfce.org>
Date:   Sat May 11 15:28:50 2013 +0200

    Force reference on files from the cache.
    
    This should protect against files that are used in a
    function after being returned from the cache, but
    destroyed in other threads.

 thunar/thunar-dnd.c            |    2 +-
 thunar/thunar-file.c           |   26 +++++++++++++++++++++-----
 thunar/thunar-history.c        |    2 ++
 thunar/thunar-session-client.c |    1 +
 thunar/thunar-standard-view.c  |    7 +++++--
 thunar/thunar-thumbnailer.c    |    2 ++
 thunar/thunar-tree-view.c      |    1 +
 7 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/thunar/thunar-dnd.c b/thunar/thunar-dnd.c
index 6a4339f..6eb07ad 100644
--- a/thunar/thunar-dnd.c
+++ b/thunar/thunar-dnd.c
@@ -179,7 +179,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 0878817..580638e 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -672,6 +672,8 @@ thunar_file_monitor_update (GFile             *path,
         default:
           break;
         }
+
+      g_object_unref (file);
     }
 }
 
@@ -1107,8 +1109,8 @@ thunar_file_get (GFile   *gfile,
   file = thunar_file_cache_lookup (gfile);
   if (G_UNLIKELY (file != NULL))
     {
-      /* take a reference for the caller */
-      g_object_ref (file);
+      /* return the file, it already has an additional ref set
+       * in thunar_file_cache_lookup */
     }
   else
     {
@@ -1173,8 +1175,8 @@ thunar_file_get_with_info (GFile     *gfile,
   file = thunar_file_cache_lookup (gfile);
   if (G_UNLIKELY (file != NULL))
     {
-      /* take a reference for the caller */
-      g_object_ref (file);
+      /* return the file, it already has an additional ref set
+       * in thunar_file_cache_lookup */
     }
   else
     {
@@ -1266,6 +1268,7 @@ thunar_file_get_async (GFile            *location,
     {
       /* call the return function with the file from the cache */
       (func) (location, file, NULL, user_data);
+      g_object_unref (file);
     }
   else
     {
@@ -1954,6 +1957,9 @@ thunar_file_accepts_drop (ThunarFile     *file,
                   suggested_action = GDK_ACTION_COPY;
                   break;
                 }
+
+              if (ofile != NULL)
+                g_object_unref (ofile);
             }
         }
     }
@@ -3878,7 +3884,8 @@ thunar_file_same_filesystem (const ThunarFile *file_a,
  * Consider using thunar_file_get() instead.
  *
  * Return value: the #ThunarFile for @file in the internal
- *               cache, or %NULL.
+ *               cache, or %NULL. If you are done with the
+ *               file, use g_object_unref to release.
  **/
 ThunarFile *
 thunar_file_cache_lookup (const GFile *file)
@@ -3900,6 +3907,14 @@ thunar_file_cache_lookup (const GFile *file)
 
   cached_file = g_hash_table_lookup (file_cache, file);
 
+  if (cached_file != NULL)
+    {
+      /* take a reference to avoid too-early releases outside the
+       * file_cache_mutex, resuling in destroyed files being used
+       * in running code */
+      g_object_ref (cached_file);
+    }
+
   G_UNLOCK (file_cache_mutex);
 
   return cached_file;
@@ -3919,6 +3934,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-history.c b/thunar/thunar-history.c
index fd99e7e..bb6012a 100644
--- a/thunar/thunar-history.c
+++ b/thunar/thunar-history.c
@@ -647,6 +647,8 @@ thunar_history_show_menu (GtkAction     *action,
               image = gtk_image_new_from_pixbuf (icon);
               g_object_unref (G_OBJECT (icon));
             }
+
+          g_object_unref (file);
         }
 
       if (image == NULL)
diff --git a/thunar/thunar-session-client.c b/thunar/thunar-session-client.c
index 3465709..628782e 100644
--- a/thunar/thunar-session-client.c
+++ b/thunar/thunar-session-client.c
@@ -292,6 +292,7 @@ thunar_session_client_restore_trash (gpointer data)
     {
       thunar_file_reload (directory);
       item_count = thunar_file_get_item_count (directory);
+      g_object_unref (directory);
     }
 
   /* continue checking for 15 seconds or files are found */
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index ad4af3a..9c2ed1b 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -1553,7 +1553,10 @@ thunar_standard_view_set_loading (ThunarStandardView *standard_view,
                 {
                   file = thunar_file_cache_lookup (first_file);
                   if (G_LIKELY (file != NULL))
-                    thunar_view_scroll_to_file (THUNAR_VIEW (standard_view), file, FALSE, TRUE, 0.0f, 0.0f);
+                    {
+                      thunar_view_scroll_to_file (THUNAR_VIEW (standard_view), file, FALSE, TRUE, 0.0f, 0.0f);
+                      g_object_unref (file);
+                    }
                 }
             }
         }
@@ -2927,7 +2930,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 195dc21..308e109 100644
--- a/thunar/thunar-thumbnailer.c
+++ b/thunar/thunar-thumbnailer.c
@@ -770,6 +770,8 @@ thunar_thumbnailer_idle_func (gpointer user_data)
               _thunar_assert_not_reached ();
             }
         }
+
+      g_object_unref (file);
     }
 
   /* remove the idle struct */
diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index bb976f3..c5b124e 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -2276,6 +2276,7 @@ thunar_tree_view_new_files (ThunarJob      *job,
     {
       /* change to the newly created folder */
       thunar_navigator_change_directory (THUNAR_NAVIGATOR (view), file);
+      g_object_unref (file);
     }
 }
 


More information about the Xfce4-commits mailing list