gstreamer/bin: Take a strong reference of the element passed into remove_element()

It might be gone once we called into the parent class' implementation so
we need to keep a strong reference around here. Also we need to ensure
that we don't accidentally steal a floating reference from the caller
here: if the element is still floating it is apparently not part of this
bin and we can directly return FALSE.
This commit is contained in:
Sebastian Dröge 2019-12-07 22:56:11 +02:00
parent bef1143df3
commit 802fa4fcb4

View file

@ -140,8 +140,15 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Bin = from_glib_borrow(ptr); let wrap: Bin = from_glib_borrow(ptr);
// If we get a floating reference passed simply return FALSE here. It can't be
// stored inside this bin, and if we continued to use it we would take ownership
// of this floating reference.
if gobject_sys::g_object_is_floating(element as *mut gobject_sys::GObject) != glib_sys::GFALSE {
return glib_sys::GFALSE;
}
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.remove_element(&wrap, &from_glib_borrow(element)) { match imp.remove_element(&wrap, &from_glib_none(element)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&wrap); err.log_with_object(&wrap);