From d3543efec248071c529c7a64445603af57328a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 8 Nov 2022 18:24:15 +0200 Subject: [PATCH] gstreamer: Manually implement `Allocator::register()` Due to a bug it causes use-after-free in versions < 1.20.5, so work around that here. --- gstreamer/Gir.toml | 4 ++++ gstreamer/src/allocator.rs | 23 +++++++++++++++++++++++ gstreamer/src/auto/allocator.rs | 8 -------- gstreamer/src/lib.rs | 1 + 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 gstreamer/src/allocator.rs diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index 22c807016..eb46140d0 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -394,6 +394,10 @@ status = "generate" [[object]] name = "Gst.Allocator" status = "generate" + [[object.function]] + name = "register" + # Steals the string name in < 1.20.5 + manual = true [[object.function]] name = "alloc" diff --git a/gstreamer/src/allocator.rs b/gstreamer/src/allocator.rs new file mode 100644 index 000000000..1a329ff77 --- /dev/null +++ b/gstreamer/src/allocator.rs @@ -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) { + 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(), + ); + } + } + } +} diff --git a/gstreamer/src/auto/allocator.rs b/gstreamer/src/auto/allocator.rs index 07da22f1b..749c2bdbf 100644 --- a/gstreamer/src/auto/allocator.rs +++ b/gstreamer/src/auto/allocator.rs @@ -26,14 +26,6 @@ impl Allocator { assert_initialized_main_thread!(); 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) { - skip_assert_initialized!(); - unsafe { - ffi::gst_allocator_register(name.to_glib_none().0, allocator.as_ref().to_glib_full()); - } - } } unsafe impl Send for Allocator {} diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 91255848c..0d3de51db 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -153,6 +153,7 @@ mod pipeline; mod allocation_params; pub use self::allocation_params::AllocationParams; +mod allocator; mod element_factory_type; pub use element_factory_type::*;