diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2017-03-17 12:58:06 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2017-04-03 11:35:51 +0300 |
commit | 58370ed6cf733380024fad3eb39334d06cfc7534 (patch) | |
tree | 00ab99aed6751c993a4c3f21e7a6cf75179d402f /gst-libs/gst/uridownloader | |
parent | 45a6449e64839ed9834dc5b1303150906576d5d9 (diff) | |
download | gstreamer-plugins-bad-58370ed6cf733380024fad3eb39334d06cfc7534.tar.gz |
uridownloader: Use a GWeakRef to the parent to prevent a reference cycle
https://bugzilla.gnome.org/show_bug.cgi?id=780140
Diffstat (limited to 'gst-libs/gst/uridownloader')
-rw-r--r-- | gst-libs/gst/uridownloader/gsturidownloader.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/gst-libs/gst/uridownloader/gsturidownloader.c b/gst-libs/gst/uridownloader/gsturidownloader.c index f54ced462..47b5e8b05 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.c +++ b/gst-libs/gst/uridownloader/gsturidownloader.c @@ -42,7 +42,7 @@ struct _GstUriDownloaderPrivate gboolean got_buffer; GMutex download_lock; /* used to restrict to one download only */ - GstElement *parent; + GWeakRef parent; GError *err; @@ -135,10 +135,7 @@ gst_uri_downloader_dispose (GObject * object) downloader->priv->download = NULL; } - if (downloader->priv->parent) { - gst_object_unref (downloader->priv->parent); - downloader->priv->parent = NULL; - } + g_weak_ref_clear (&downloader->priv->parent); G_OBJECT_CLASS (gst_uri_downloader_parent_class)->dispose (object); } @@ -173,8 +170,7 @@ void gst_uri_downloader_set_parent (GstUriDownloader * downloader, GstElement * parent) { - gst_object_replace ((GstObject **) & downloader->priv->parent, - GST_OBJECT_CAST (parent)); + g_weak_ref_set (&downloader->priv->parent, parent); } static gboolean @@ -280,25 +276,25 @@ gst_uri_downloader_bus_handler (GstBus * bus, g_error_free (err); g_free (dbg_info); } else if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT) { + GstElement *parent = g_weak_ref_get (&downloader->priv->parent); + /* post the same need-context as if it was from the parent and then * get it to our internal element that requested it */ - if (downloader->priv->parent && GST_IS_ELEMENT (GST_MESSAGE_SRC (message))) { + if (parent && GST_IS_ELEMENT (GST_MESSAGE_SRC (message))) { const gchar *context_type; GstContext *context; GstElement *msg_src = GST_ELEMENT_CAST (GST_MESSAGE_SRC (message)); gst_message_parse_context_type (message, &context_type); - context = - gst_element_get_context (downloader->priv->parent, context_type); + context = gst_element_get_context (parent, context_type); /* No context, request one */ if (!context) { GstMessage *need_context_msg = - gst_message_new_need_context (GST_OBJECT_CAST (downloader-> - priv->parent), context_type); - gst_element_post_message (downloader->priv->parent, need_context_msg); - context = - gst_element_get_context (downloader->priv->parent, context_type); + gst_message_new_need_context (GST_OBJECT_CAST (parent), + context_type); + gst_element_post_message (parent, need_context_msg); + context = gst_element_get_context (parent, context_type); } if (context) { @@ -306,6 +302,8 @@ gst_uri_downloader_bus_handler (GstBus * bus, gst_context_unref (context); } } + if (parent) + gst_object_unref (parent); } gst_message_unref (message); |