[grilo-plugins] plugins: Fix possible crash when registering sources



commit 5973947051d6ca789965c92c5c33cf66cadd3f25
Author: Bastien Nocera <hadess hadess net>
Date:   Tue May 7 16:11:05 2013 +0200

    plugins: Fix possible crash when registering sources
    
    Calls to grl_registry_register_source() can lead to the source
    being unref'ed (for example, a video player not interested in audio-
    only sources would do that in "source-added"), so we must be careful
    when using the source after registration.
    
    Both the dmap and podcasts plugins used the source after registration,
    so we must make sure they don't use freed memory.

 src/dmap/grl-dmap.c         |    7 +++++--
 src/podcasts/grl-podcasts.c |    4 ++++
 2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/dmap/grl-dmap.c b/src/dmap/grl-dmap.c
index a2c3d1d..07d2374 100644
--- a/src/dmap/grl-dmap.c
+++ b/src/dmap/grl-dmap.c
@@ -351,12 +351,15 @@ service_added_cb (DMAPMdnsBrowser *browser,
 
   GRL_DEBUG (__FUNCTION__);
 
+  g_object_add_weak_pointer (G_OBJECT (source), (gpointer *) &source);
   grl_registry_register_source (registry,
                                 plugin,
                                 GRL_SOURCE (source),
                                 NULL);
-
-  g_hash_table_insert (sources, g_strdup (service->name), g_object_ref (source));
+  if (source != NULL) {
+    g_hash_table_insert (sources, g_strdup (service->name), g_object_ref (source));
+    g_object_remove_weak_pointer (G_OBJECT (source), (gpointer *) &source);
+  }
 }
 
 static void
diff --git a/src/podcasts/grl-podcasts.c b/src/podcasts/grl-podcasts.c
index 9c7c338..32faef4 100644
--- a/src/podcasts/grl-podcasts.c
+++ b/src/podcasts/grl-podcasts.c
@@ -282,10 +282,14 @@ grl_podcasts_plugin_init (GrlRegistry *registry,
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
   GrlPodcastsSource *source = grl_podcasts_source_new ();
+  g_object_add_weak_pointer (G_OBJECT (source), (gpointer *) &source);
   grl_registry_register_source (registry,
                                 plugin,
                                 GRL_SOURCE (source),
                                 NULL);
+  if (source == NULL)
+    return TRUE;
+  g_object_remove_weak_pointer (G_OBJECT (source), (gpointer *) &source);
 
   source->priv->cache_time = DEFAULT_CACHE_TIME;
   if (!configs || !configs->data) {


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