[grilo-plugins] tracker: Keep references to GrlTrackerSources in global hash table



commit 45e2abe2609f3fbf0e50c889d7043507f7968f49
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Dec 23 10:17:39 2014 +0000

    tracker: Keep references to GrlTrackerSources in global hash table
    
    Force the GrlTrackerSources in the grl_tracker_source_sources to stay
    alive while they are in the hash table. Otherwise, due to the mismatch
    between Tracker events and signalling changes to the hash table, we can
    end up using finalised members from the hash table in (e.g.)
    tracker_evt_update_orphan_item_cb() (I think).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733582

 src/tracker/grl-tracker-source-notif.c |    6 +++++-
 src/tracker/grl-tracker-source.c       |   18 +++++++++++++-----
 2 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/src/tracker/grl-tracker-source-notif.c b/src/tracker/grl-tracker-source-notif.c
index c745fd5..3e23024 100644
--- a/src/tracker/grl-tracker-source-notif.c
+++ b/src/tracker/grl-tracker-source-notif.c
@@ -122,7 +122,9 @@ tracker_evt_update_source_add (tracker_evt_update_t *evt,
                           NULL);
     g_hash_table_insert (grl_tracker_source_sources_modified,
                          (gpointer) grl_tracker_source_get_tracker_source (source),
-                        source);
+                         g_object_ref (source));
+  } else {
+    g_object_ref (source);
   }
 
   priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
@@ -133,6 +135,8 @@ tracker_evt_update_source_add (tracker_evt_update_t *evt,
 
   GRL_DEBUG ("Preadd source p=%p name=%s id=%s count=%u",
              source, source_name, id, priv->notification_ref);
+
+  g_object_unref (source);
 }
 
 static void
diff --git a/src/tracker/grl-tracker-source.c b/src/tracker/grl-tracker-source.c
index 858565b..4f01580 100644
--- a/src/tracker/grl-tracker-source.c
+++ b/src/tracker/grl-tracker-source.c
@@ -228,7 +228,7 @@ grl_tracker_add_source (GrlTrackerSource *source)
                          grl_tracker_source_get_tracker_source (source));
     g_hash_table_insert (grl_tracker_source_sources,
                          (gpointer) grl_tracker_source_get_tracker_source (source),
-                         source);
+                         g_object_ref (source));
     priv->state = GRL_TRACKER_SOURCE_STATE_RUNNING;
     grl_registry_register_source (grl_registry_get_default (),
                                   grl_tracker_plugin,
@@ -364,6 +364,7 @@ tracker_get_datasource_cb (GObject             *object,
                              "tracker-datasource", datasource,
                              NULL);
       grl_tracker_add_source (source);
+      g_object_unref (source);
       g_free (source_name);
     }
   }
@@ -407,9 +408,12 @@ grl_tracker_source_sources_init (void)
 
   grl_tracker_item_cache =
     grl_tracker_source_cache_new (TRACKER_ITEM_CACHE_SIZE);
-  grl_tracker_source_sources = g_hash_table_new (g_str_hash, g_str_equal);
-  grl_tracker_source_sources_modified = g_hash_table_new (g_str_hash,
-                                                          g_str_equal);
+  grl_tracker_source_sources = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                                      NULL, g_object_unref);
+  grl_tracker_source_sources_modified = g_hash_table_new_full (g_str_hash,
+                                                               g_str_equal,
+                                                               NULL,
+                                                               g_object_unref);
 
 
   if (grl_tracker_connection != NULL) {
@@ -426,8 +430,12 @@ grl_tracker_source_sources_init (void)
                                              (GAsyncReadyCallback) tracker_get_datasources_cb,
                                              NULL);
     } else {
+      GrlTrackerSource *source;
+
       /* One source to rule them all. */
-      grl_tracker_add_source (grl_tracker_source_new (grl_tracker_connection));
+      source = grl_tracker_source_new (grl_tracker_connection);
+      grl_tracker_add_source (source);
+      g_object_unref (source);
     }
   }
 }


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