From 7b8070c55da2de60ead2d9a99dd9bcfecc3aaa07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 9 Jul 2019 19:18:53 +0300 Subject: [PATCH] Use slice::from_raw_parts instead of Vec::from_raw_parts The latter must only be called on memory that was allocated by Rust for a Vec and will cause crashes depending on the platform otherwise. Also it would free the memory as if a Vec was allocated, which would free memory that we don't own to begin with. --- src/ndivideosrc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ndivideosrc.rs b/src/ndivideosrc.rs index 0b31b2f21..98d75e9ee 100644 --- a/src/ndivideosrc.rs +++ b/src/ndivideosrc.rs @@ -16,7 +16,7 @@ use gst_video; use std::sync::Mutex; use std::{i32, u32}; -use std::ptr; +use std::{slice, ptr}; use connect_ndi; use ndi_struct; @@ -502,7 +502,7 @@ impl BaseSrcImpl for NdiVideoSrc { let buff_size = (video_frame.yres * video_frame.line_stride_in_bytes) as usize; let mut buffer = gst::Buffer::with_size(buff_size).unwrap(); { - let vec = Vec::from_raw_parts(video_frame.p_data as *mut u8, buff_size, buff_size); + let data = slice::from_raw_parts(video_frame.p_data as *mut u8, buff_size); // Newtek NDI yields times in 100ns intervals since the Unix Time let pts: gst::ClockTime = (pts * 100).into(); @@ -522,7 +522,7 @@ impl BaseSrcImpl for NdiVideoSrc { buffer.set_offset(timestamp_data.offset); timestamp_data.offset += 1; buffer.set_offset_end(timestamp_data.offset); - buffer.copy_from_slice(0, &vec).unwrap(); + buffer.copy_from_slice(0, data).unwrap(); } gst_log!(self.cat, obj: element, "Produced buffer {:?}", buffer);