[gnome-photos/gnome-3-20] base-item: Avoid pointing to invalid memory



commit 4deff81c29ee2562c08447e57cf59e4a3e648745
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Apr 20 09:26:00 2016 +0200

    base-item: Avoid pointing to invalid memory
    
    We should keep our own copy of G_FILE_ATTRIBUTE_THUMBNAIL_PATH. This
    was working earlier because we used to leak the GFileInfos.
    
    Fall out from
    a0aeb74da414ccebabf208d4753c9fab5594c929 and
    d93b3f5710f725e719952e56e5fce16da89bc010
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765295

 src/photos-base-item.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 886eecc..91f8a8f 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -80,7 +80,6 @@ struct _PhotosBaseItemPrivate
   gboolean collection;
   gboolean failed_thumbnailing;
   gboolean favorite;
-  const gchar *thumb_path;
   gchar *author;
   gchar *default_app_name;
   gchar *filename;
@@ -91,6 +90,7 @@ struct _PhotosBaseItemPrivate
   gchar *name_fallback;
   gchar *rdf_type;
   gchar *resource_urn;
+  gchar *thumb_path;
   gchar *type_description;
   gchar *uri;
   gdouble exposure_time;
@@ -591,7 +591,7 @@ photos_base_item_refresh_thumb_path_pixbuf (GObject *source_object, GAsyncResult
       uri = g_file_get_uri (file);
       g_warning ("Unable to create pixbuf from %s: %s", uri, error->message);
       priv->failed_thumbnailing = TRUE;
-      priv->thumb_path = NULL;
+      g_clear_pointer (&priv->thumb_path, g_free);
       g_file_delete_async (file, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
       photos_base_item_set_failed_icon (self);
       g_free (uri);
@@ -630,7 +630,7 @@ photos_base_item_refresh_thumb_path_read (GObject *source_object, GAsyncResult *
       uri = g_file_get_uri (file);
       g_warning ("Unable to read file at %s: %s", uri, error->message);
       priv->failed_thumbnailing = TRUE;
-      priv->thumb_path = NULL;
+      g_clear_pointer (&priv->thumb_path, g_free);
       g_file_delete_async (file, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
       photos_base_item_set_failed_icon (self);
       g_free (uri);
@@ -675,6 +675,8 @@ photos_base_item_thumbnail_path_info (GObject *source_object, GAsyncResult *res,
   GFile *file = G_FILE (source_object);
   GFileInfo *info = NULL;
 
+  g_clear_pointer (&priv->thumb_path, g_free);
+
   info = g_file_query_info_finish (file, res, &error);
   if (error != NULL)
     {
@@ -685,7 +687,7 @@ photos_base_item_thumbnail_path_info (GObject *source_object, GAsyncResult *res,
       goto out;
     }
 
-  priv->thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
+  priv->thumb_path = g_strdup (g_file_info_get_attribute_byte_string (info, 
G_FILE_ATTRIBUTE_THUMBNAIL_PATH));
   if (priv->thumb_path != NULL)
     {
       photos_base_item_refresh_thumb_path (self);
@@ -743,6 +745,8 @@ photos_base_item_file_query_info (GObject *source_object, GAsyncResult *res, gpo
   GFile *file = G_FILE (source_object);
   GFileInfo *info = NULL;
 
+  g_clear_pointer (&priv->thumb_path, g_free);
+
   info = g_file_query_info_finish (file, res, &error);
   if (error != NULL)
     {
@@ -753,7 +757,7 @@ photos_base_item_file_query_info (GObject *source_object, GAsyncResult *res, gpo
       goto out;
     }
 
-  priv->thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
+  priv->thumb_path = g_strdup (g_file_info_get_attribute_byte_string (info, 
G_FILE_ATTRIBUTE_THUMBNAIL_PATH));
   if (priv->thumb_path != NULL)
     photos_base_item_refresh_thumb_path (self);
   else
@@ -1531,6 +1535,7 @@ photos_base_item_finalize (GObject *object)
   g_free (priv->name_fallback);
   g_free (priv->rdf_type);
   g_free (priv->resource_urn);
+  g_free (priv->thumb_path);
   g_free (priv->type_description);
   g_free (priv->uri);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]