Commit d20bceb6 authored by François Laignel's avatar François Laignel Committed by Sebastian Dröge

0.11: Fix memory issue building a `Sample` with an `info` `Structure`

This is a workaround to get the fix from PR #113 on branch 0.11 without
breaking the API.
parent f9d7c579
...@@ -40,13 +40,13 @@ impl GstRc<SampleRef> { ...@@ -40,13 +40,13 @@ impl GstRc<SampleRef> {
) -> Self { ) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let info = info.map(|i| i.as_ptr()).unwrap_or(ptr::null()); let info = info.map(|i| ffi::gst_structure_copy(i.as_ptr())).unwrap_or(ptr::null_mut());
from_glib_full(ffi::gst_sample_new( from_glib_full(ffi::gst_sample_new(
buffer.to_glib_none().0, buffer.to_glib_none().0,
caps.to_glib_none().0, caps.to_glib_none().0,
mut_override(segment.to_glib_none().0), mut_override(segment.to_glib_none().0),
mut_override(info), info,
)) ))
} }
} }
...@@ -122,3 +122,28 @@ impl fmt::Debug for SampleRef { ...@@ -122,3 +122,28 @@ impl fmt::Debug for SampleRef {
unsafe impl Sync for SampleRef {} unsafe impl Sync for SampleRef {}
unsafe impl Send for SampleRef {} unsafe impl Send for SampleRef {}
#[cfg(test)]
mod tests {
#[test]
fn test_sample_new_with_info() {
use GenericFormattedValue;
use Sample;
use Structure;
::init().unwrap();
let info = Structure::builder("sample.info")
.field("f3", &123i32)
.build();
let sample = Sample::new::<GenericFormattedValue>(
None,
None,
None,
Some(info.as_ref()),
);
assert!(sample.get_info().is_some());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment