mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-02-20 12:56:22 +00:00
Fix memory issue building a Sample
with an info
Structure
The following code in a `[test]`:
``` rust
let info = Structure::builder("sample.info")
.field("f3", &123i32)
.build();
let sample = Sample:🆕:<GenericFormattedValue>(
None,
None,
None,
Some(info.as_ref())
);
```
generates one of the followings executing `cargo test`:
```
- segmentation fault
- signal: 6, SIGABRT: process abort signal
- signal: 11, SIGSEGV: invalid memory reference
```
This is due to `ffi::gst_sample_new` expecting to take ownership of the `info`
`Structure`.
This commit is contained in:
parent
d2272fefa7
commit
f4d57a6652
1 changed files with 25 additions and 4 deletions
|
@ -22,6 +22,7 @@ use Caps;
|
||||||
use FormattedSegment;
|
use FormattedSegment;
|
||||||
use FormattedValue;
|
use FormattedValue;
|
||||||
use Segment;
|
use Segment;
|
||||||
|
use Structure;
|
||||||
use StructureRef;
|
use StructureRef;
|
||||||
|
|
||||||
pub type Sample = GstRc<SampleRef>;
|
pub type Sample = GstRc<SampleRef>;
|
||||||
|
@ -36,16 +37,16 @@ impl GstRc<SampleRef> {
|
||||||
buffer: Option<&Buffer>,
|
buffer: Option<&Buffer>,
|
||||||
caps: Option<&Caps>,
|
caps: Option<&Caps>,
|
||||||
segment: Option<&FormattedSegment<F>>,
|
segment: Option<&FormattedSegment<F>>,
|
||||||
info: Option<&StructureRef>,
|
info: Option<Structure>,
|
||||||
) -> 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| i.into_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),
|
segment.to_glib_none().0,
|
||||||
mut_override(info),
|
mut_override(info),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ impl GstRc<SampleRef> {
|
||||||
buffer_list: Option<&BufferList>,
|
buffer_list: Option<&BufferList>,
|
||||||
caps: Option<&Caps>,
|
caps: Option<&Caps>,
|
||||||
segment: Option<&FormattedSegment<F>>,
|
segment: Option<&FormattedSegment<F>>,
|
||||||
info: Option<&StructureRef>,
|
info: Option<Structure>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
let sample = Self::new(None, caps, segment, info);
|
let sample = Self::new(None, caps, segment, info);
|
||||||
|
@ -122,3 +123,23 @@ 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));
|
||||||
|
|
||||||
|
assert!(sample.get_info().is_some());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue