Skip to content

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

François Laignel requested to merge fengalin:sample_info into master

The following code in a [test]:

let info = Structure::builder("sample.info")
    .field("f3", &123i32)
    .build();
let sample = Sample::new::<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

Looking at gst_sample_new, it appears that the GstStructure argument info is transfer full, which makes sense since GstStructure "does not have a refcount because it usually is part of a higher level object" and "provides a means to enforce mutability using the refcount of the parent with the gst_structure_set_parent_refcount() method" (source).

So my best guess is to have Sample::new and Sample::with_buffer_list consume the info argument.

I also took the liberty to remove mut_override for the segment argument as it is declared as const GstSegment *segment in gst_sample_new. Or was it fixed from a previous version of GStreamer?

Merge request reports