basetransform: Don't leak any output buffer if prepare_output_buffer fails

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1290>
This commit is contained in:
Sebastian Dröge 2023-06-30 10:33:30 +03:00
parent 38420c7aab
commit d77f983b02

View file

@ -570,6 +570,13 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
PrepareOutputBufferSuccess::Buffer(from_glib_full(outbuf))
}
})
.map_err(|err| {
if outbuf != buf as *mut _ {
drop(Option::<gst::Buffer>::from_glib_full(outbuf));
}
err
})
})
.unwrap_or(Err(gst::FlowError::NotSupported))
}
@ -1140,6 +1147,8 @@ unsafe extern "C" fn base_transform_prepare_output_buffer<T: BaseTransformImpl>(
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) => {