[Xfce4-commits] <thunar:master> Fix sefaults when loading image icons.

Nick Schermer noreply at xfce.org
Sat Jul 24 19:50:01 CEST 2010


Updating branch refs/heads/master
         to 00db7f70831a33db9490a961f8043b4f78210ee8 (commit)
       from 0cb2d9c003b466fe2c1d6496f3738fc1e2d283f4 (commit)

commit 00db7f70831a33db9490a961f8043b4f78210ee8
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Jul 24 19:45:53 2010 +0200

    Fix sefaults when loading image icons.
    
    Loading the icon view on my camera crashed Thunar in
    multiple places. First the g_loadable_icon_load was
    passed the wrong variable and there was a memory
    corruption (crash and visible in valgrind) because the
    preview::icon was unreffed, while this reference is
    owned by the GFileInfo.

 thunar/thunar-file.c         |   19 +++++++++++++++++--
 thunar/thunar-icon-factory.c |    5 +----
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index e8ebe76..b9b30dc 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -2701,13 +2701,28 @@ thunar_file_get_custom_icon (const ThunarFile *file)
 
 
 
+/**
+ * thunar_file_get_preview_icon:
+ * @file : a #ThunarFile instance.
+ *
+ * Returns the preview icon for @file if any, else %NULL is returned.
+ *
+ * Return value: the custom icon for @file or %NULL, the GIcon is owner
+ * by the file, so do not unref it.
+ **/
 GIcon *
 thunar_file_get_preview_icon (const ThunarFile *file)
 {
+  GObject *icon;
+
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
-  _thunar_return_val_if_fail (file->info != NULL, NULL);
+  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->info), NULL);
+
+  icon = g_file_info_get_attribute_object (file->info, "preview::icon");
+  if (G_LIKELY (icon != NULL))
+    return G_ICON (icon);
 
-  return G_ICON (g_file_info_get_attribute_object (file->info, "preview::icon"));
+  return NULL;
 }
 
 
diff --git a/thunar/thunar-icon-factory.c b/thunar/thunar-icon-factory.c
index cd2a003..bf7fc9e 100644
--- a/thunar/thunar-icon-factory.c
+++ b/thunar/thunar-icon-factory.c
@@ -881,7 +881,7 @@ thunar_icon_factory_load_file_icon (ThunarIconFactory  *factory,
           else if (G_IS_LOADABLE_ICON (gicon))
             {
               /* we have a loadable icon, try to open it for reading */
-              stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), icon_size, 
+              stream = g_loadable_icon_load (G_LOADABLE_ICON (gicon), icon_size,
                                              NULL, NULL, NULL);
 
               /* check if we have a valid input stream */
@@ -895,9 +895,6 @@ thunar_icon_factory_load_file_icon (ThunarIconFactory  *factory,
                 }
             }
 
-          /* release the preview icon */
-          g_object_unref (gicon);
-
           /* return the icon if we have one */
           if (icon != NULL)
             return icon;



More information about the Xfce4-commits mailing list