[gnome-photos] collection-icon-watcher: Be careful with the lifetime of the collection



commit 3064112bd45a8cdaa62be7a074a1d534fb994387
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jan 24 16:17:34 2014 +0100

    collection-icon-watcher: Be careful with the lifetime of the collection
    
    ... because it is not owned by the watcher. Instead the watcher is
    owned by it. We keep a reference to the watcher while doing various
    asynchronous operations, but that does not mean that the collection is
    still valid. It might have been destroyed while we were waiting for the
    asynchronous operations to complete.
    
    Therefore, add a weak reference to the collection and check its
    validity wherever applicable.

 src/photos-collection-icon-watcher.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/src/photos-collection-icon-watcher.c b/src/photos-collection-icon-watcher.c
index f4691c3..843e8b8 100644
--- a/src/photos-collection-icon-watcher.c
+++ b/src/photos-collection-icon-watcher.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2013 Red Hat, Inc.
+ * Copyright © 2013, 2014 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -70,12 +70,13 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhotosCollectionIconWatcher, photos_collection_icon_
 static void
 photos_collection_icon_watcher_create_collection_icon (PhotosCollectionIconWatcher *self)
 {
+  PhotosCollectionIconWatcherPrivate *priv = self->priv;
   GIcon *icon;
   GList *icons = NULL;
   GList *l;
   gint size;
 
-  for (l = self->priv->items; l != NULL; l = l->next)
+  for (l = priv->items; l != NULL; l = l->next)
     {
       GdkPixbuf *pristine_icon;
       PhotosBaseItem *item = PHOTOS_BASE_ITEM (l->data);
@@ -88,7 +89,8 @@ photos_collection_icon_watcher_create_collection_icon (PhotosCollectionIconWatch
   size = photos_utils_get_icon_size ();
   icon = photos_utils_create_collection_icon (size, icons);
 
-  g_signal_emit (self, signals[ICON_UPDATED], 0, icon);
+  if (priv->collection != NULL)
+    g_signal_emit (self, signals[ICON_UPDATED], 0, icon);
 
   g_list_free_full (icons, g_object_unref);
   g_clear_object (&icon);
@@ -304,6 +306,9 @@ photos_collection_icon_watcher_start (PhotosCollectionIconWatcher *self)
   if (G_UNLIKELY (priv->queue == NULL))
     return;
 
+  if (priv->collection == NULL)
+    return;
+
   id = photos_base_item_get_id (priv->collection);
   query = photos_query_builder_collection_icon_query (id);
   photos_tracker_queue_select (priv->queue,
@@ -367,11 +372,13 @@ photos_collection_icon_watcher_set_property (GObject *object,
                                              GParamSpec *pspec)
 {
   PhotosCollectionIconWatcher *self = PHOTOS_COLLECTION_ICON_WATCHER (object);
+  PhotosCollectionIconWatcherPrivate *priv = self->priv;
 
   switch (prop_id)
     {
     case PROP_COLLECTION:
-      self->priv->collection = PHOTOS_BASE_ITEM (g_value_get_object (value)); /* self is owned by collection 
*/
+      priv->collection = PHOTOS_BASE_ITEM (g_value_get_object (value)); /* self is owned by collection */
+      g_object_add_weak_pointer (G_OBJECT (priv->collection), (gpointer *) &priv->collection);
       break;
 
     default:


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