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:
Vivia Nikolaidou 2015-08-24 21:04:37 +03:00 committed by Sebastian Dröge
parent 2534e39e55
commit ee1bbe2f15
2 changed files with 14 additions and 1 deletions

View file

@ -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_ELEMENT (element), FALSE);
g_return_val_if_fail (GST_ELEMENT_CAST (bin) != element, FALSE);
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));
/* 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 (element);
@ -1564,6 +1569,13 @@ no_state_recalc:
return TRUE;
/* 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:
{
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_ELEMENT (element), FALSE);
g_return_val_if_fail (GST_ELEMENT_CAST (bin) != element, FALSE);
bclass = GST_BIN_GET_CLASS (bin);

View file

@ -697,7 +697,7 @@ GST_START_TEST (test_add_self)
bin = gst_bin_new (NULL);
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);
}