gstreamer: Manually implement Allocator::register()

Due to a bug it causes use-after-free in versions < 1.20.5, so work
around that here.
This commit is contained in:
Sebastian Dröge 2022-11-08 18:24:15 +02:00
parent 32c432655f
commit d3543efec2
4 changed files with 28 additions and 8 deletions

View file

@ -394,6 +394,10 @@ status = "generate"
[[object]] [[object]]
name = "Gst.Allocator" name = "Gst.Allocator"
status = "generate" status = "generate"
[[object.function]]
name = "register"
# Steals the string name in < 1.20.5
manual = true
[[object.function]] [[object.function]]
name = "alloc" name = "alloc"

View file

@ -0,0 +1,23 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::Allocator;
use glib::translate::*;
use glib::IsA;
impl Allocator {
#[doc(alias = "gst_allocator_register")]
pub fn register(name: &str, allocator: &impl IsA<Allocator>) {
skip_assert_initialized!();
unsafe {
// See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3364
if crate::version() < (1, 20, 5, 0) {
ffi::gst_allocator_register(name.to_glib_full(), allocator.as_ref().to_glib_full());
} else {
ffi::gst_allocator_register(
name.to_glib_none().0,
allocator.as_ref().to_glib_full(),
);
}
}
}
}

View file

@ -26,14 +26,6 @@ impl Allocator {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gst_allocator_find(name.to_glib_none().0)) } unsafe { from_glib_full(ffi::gst_allocator_find(name.to_glib_none().0)) }
} }
#[doc(alias = "gst_allocator_register")]
pub fn register(name: &str, allocator: &impl IsA<Allocator>) {
skip_assert_initialized!();
unsafe {
ffi::gst_allocator_register(name.to_glib_none().0, allocator.as_ref().to_glib_full());
}
}
} }
unsafe impl Send for Allocator {} unsafe impl Send for Allocator {}

View file

@ -153,6 +153,7 @@ mod pipeline;
mod allocation_params; mod allocation_params;
pub use self::allocation_params::AllocationParams; pub use self::allocation_params::AllocationParams;
mod allocator;
mod element_factory_type; mod element_factory_type;
pub use element_factory_type::*; pub use element_factory_type::*;