From d20bceb68f9e5bb2060e2b163d8d25b465e9176d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Tue, 12 Jun 2018 00:02:04 +0200 Subject: [PATCH] 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. --- gstreamer/src/sample.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gstreamer/src/sample.rs b/gstreamer/src/sample.rs index 5d33f3372..8e407a0a2 100644 --- a/gstreamer/src/sample.rs +++ b/gstreamer/src/sample.rs @@ -40,13 +40,13 @@ impl GstRc { ) -> Self { assert_initialized_main_thread!(); 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( buffer.to_glib_none().0, caps.to_glib_none().0, mut_override(segment.to_glib_none().0), - mut_override(info), + info, )) } } @@ -122,3 +122,28 @@ impl fmt::Debug for SampleRef { unsafe impl Sync 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::( + None, + None, + None, + Some(info.as_ref()), + ); + + assert!(sample.get_info().is_some()); + } +}