summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2013-05-07 16:11:05 +0200
committerJuan A. Suarez Romero <jasuarez@igalia.com>2013-05-07 14:19:42 +0000
commit5973947051d6ca789965c92c5c33cf66cadd3f25 (patch)
treecb821a3c73e154c538048d0e086a9e6c6f81b1aa
parent6ac1d095f4a3b0beec16637212039041e9d0bf88 (diff)
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.
-rw-r--r--src/dmap/grl-dmap.c7
-rw-r--r--src/podcasts/grl-podcasts.c4
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) {