From d77f983b02db4ae032dd5dfa0818eb73f20c7304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 30 Jun 2023 10:33:30 +0300 Subject: [PATCH] basetransform: Don't leak any output buffer if `prepare_output_buffer` fails Part-of: --- gstreamer-base/src/subclass/base_transform.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gstreamer-base/src/subclass/base_transform.rs b/gstreamer-base/src/subclass/base_transform.rs index 754745681..c1ee85c3d 100644 --- a/gstreamer-base/src/subclass/base_transform.rs +++ b/gstreamer-base/src/subclass/base_transform.rs @@ -570,6 +570,13 @@ impl BaseTransformImplExt for T { PrepareOutputBufferSuccess::Buffer(from_glib_full(outbuf)) } }) + .map_err(|err| { + if outbuf != buf as *mut _ { + drop(Option::::from_glib_full(outbuf)); + } + + err + }) }) .unwrap_or(Err(gst::FlowError::NotSupported)) } @@ -1140,6 +1147,8 @@ unsafe extern "C" fn base_transform_prepare_output_buffer( true => InputBuffer::Writable(gst::BufferRef::from_mut_ptr(inbuf)), }; + *outbuf = ptr::null_mut(); + gst::panic_to_error!(imp, gst::FlowReturn::Error, { match imp.prepare_output_buffer(buffer) { Ok(PrepareOutputBufferSuccess::InputBuffer) => {