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.
This commit is contained in:
Wim Taymans 2006-07-21 10:40:25 +00:00
parent 626d7a1fb2
commit c345ebb06a
2 changed files with 29 additions and 9 deletions

View file

@ -1,3 +1,9 @@
2006-07-21 Wim Taymans <wim@fluendo.com>
* gst/gstparse.c: (gst_parse_launch):
Protect recursive calls to _parse with a recursive mutex
and busy flag.
2006-07-21 Wim Taymans <wim@fluendo.com>
* tests/check/gst/gstpad.c: (GST_START_TEST):

View file

@ -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)) {
g_static_rec_mutex_lock (&flex_lock);
if (flex_busy)
goto recursive_call;
flex_busy = TRUE;
element = _gst_parse_launch (pipeline_description, error);
g_static_mutex_unlock (&flex_lock);
} else {
GST_WARNING ("gst_parse_launch() cannot be nested");
}
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;
}
}