mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
bin: Make sure we don't add/remove a bin to/from itself
Doing so would deadlock from trying to acquire the object lock twice https://bugzilla.gnome.org/show_bug.cgi?id=754036
This commit is contained in:
parent
2534e39e55
commit
ee1bbe2f15
2 changed files with 14 additions and 1 deletions
13
gst/gstbin.c
13
gst/gstbin.c
|
@ -1290,6 +1290,7 @@ gst_bin_add (GstBin * bin, GstElement * element)
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
||||||
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
|
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
|
||||||
|
g_return_val_if_fail (GST_ELEMENT_CAST (bin) != element, FALSE);
|
||||||
|
|
||||||
bclass = GST_BIN_GET_CLASS (bin);
|
bclass = GST_BIN_GET_CLASS (bin);
|
||||||
|
|
||||||
|
@ -1333,6 +1334,10 @@ gst_bin_remove_func (GstBin * bin, GstElement * element)
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (bin, "element :%s", GST_ELEMENT_NAME (element));
|
GST_DEBUG_OBJECT (bin, "element :%s", GST_ELEMENT_NAME (element));
|
||||||
|
|
||||||
|
/* we obviously can't remove ourself from ourself */
|
||||||
|
if (G_UNLIKELY (element == GST_ELEMENT_CAST (bin)))
|
||||||
|
goto removing_itself;
|
||||||
|
|
||||||
GST_OBJECT_LOCK (bin);
|
GST_OBJECT_LOCK (bin);
|
||||||
|
|
||||||
GST_OBJECT_LOCK (element);
|
GST_OBJECT_LOCK (element);
|
||||||
|
@ -1564,6 +1569,13 @@ no_state_recalc:
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
/* ERROR handling */
|
/* ERROR handling */
|
||||||
|
removing_itself:
|
||||||
|
{
|
||||||
|
GST_OBJECT_LOCK (bin);
|
||||||
|
g_warning ("Cannot remove bin '%s' from itself", GST_ELEMENT_NAME (bin));
|
||||||
|
GST_OBJECT_UNLOCK (bin);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
not_in_bin:
|
not_in_bin:
|
||||||
{
|
{
|
||||||
g_warning ("Element '%s' is not in bin '%s'", elem_name,
|
g_warning ("Element '%s' is not in bin '%s'", elem_name,
|
||||||
|
@ -1603,6 +1615,7 @@ gst_bin_remove (GstBin * bin, GstElement * element)
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
||||||
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
|
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
|
||||||
|
g_return_val_if_fail (GST_ELEMENT_CAST (bin) != element, FALSE);
|
||||||
|
|
||||||
bclass = GST_BIN_GET_CLASS (bin);
|
bclass = GST_BIN_GET_CLASS (bin);
|
||||||
|
|
||||||
|
|
|
@ -697,7 +697,7 @@ GST_START_TEST (test_add_self)
|
||||||
bin = gst_bin_new (NULL);
|
bin = gst_bin_new (NULL);
|
||||||
fail_unless (bin != NULL, "Could not create bin");
|
fail_unless (bin != NULL, "Could not create bin");
|
||||||
|
|
||||||
ASSERT_WARNING (gst_bin_add (GST_BIN (bin), bin));
|
ASSERT_CRITICAL (gst_bin_add (GST_BIN (bin), bin));
|
||||||
|
|
||||||
gst_object_unref (bin);
|
gst_object_unref (bin);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue