From c345ebb06a602d884bd2a1c0c675e50e5f57cba3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 21 Jul 2006 10:40:25 +0000 Subject: gst/gstparse.c: Protect recursive calls to _parse with a recursive mutex and busy flag. Original commit message from CVS: * gst/gstparse.c: (gst_parse_launch): Protect recursive calls to _parse with a recursive mutex and busy flag. --- gst/gstparse.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'gst/gstparse.c') diff --git a/gst/gstparse.c b/gst/gstparse.c index 7847952f6..f966b5156 100644 --- a/gst/gstparse.c +++ b/gst/gstparse.c @@ -36,6 +36,10 @@ #include "gstparse.h" #include "gstinfo.h" +/* the need for the mutex will go away with flex 2.5.6 */ +static gboolean flex_busy = FALSE; +static GStaticRecMutex flex_lock = G_STATIC_REC_MUTEX_INIT; + extern GstElement *_gst_parse_launch (const gchar *, GError **); /** @@ -136,21 +140,31 @@ gst_parse_launchv (const gchar ** argv, GError ** error) GstElement * gst_parse_launch (const gchar * pipeline_description, GError ** error) { - GstElement *element = NULL; - static GStaticMutex flex_lock = G_STATIC_MUTEX_INIT; + GstElement *element; g_return_val_if_fail (pipeline_description != NULL, NULL); GST_CAT_INFO (GST_CAT_PIPELINE, "parsing pipeline description %s", pipeline_description); - /* the need for the mutex will go away with flex 2.5.6 */ - if (g_static_mutex_trylock (&flex_lock)) { - element = _gst_parse_launch (pipeline_description, error); - g_static_mutex_unlock (&flex_lock); - } else { - GST_WARNING ("gst_parse_launch() cannot be nested"); - } + g_static_rec_mutex_lock (&flex_lock); + if (flex_busy) + goto recursive_call; + flex_busy = TRUE; + + element = _gst_parse_launch (pipeline_description, error); + + flex_busy = FALSE; + g_static_rec_mutex_unlock (&flex_lock); return element; + + /* ERRORS */ +recursive_call: + { + GST_WARNING ("calls to gst_parse_launch() cannot be nested"); + g_static_rec_mutex_unlock (&flex_lock); + g_warning ("calls to gst_parse_launch() cannot be nested"); + return NULL; + } } -- cgit v1.2.3