Skip to content

Commit

Permalink
Deallocate memory
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantSparks committed Jul 23, 2024
1 parent 83dc4d3 commit c9a90fb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,12 @@ impl VideoFrame {
panic!("Invalid line stride in bytes: {}", line_stride_in_bytes);
}

let p_metadata = if raw.p_metadata.is_null() {
ptr::null()
} else {
unsafe { CString::from_raw(raw.p_metadata as *mut c_char).into_raw() }
};

VideoFrame {
xres: raw.xres,
yres: raw.yres,
Expand All @@ -573,7 +579,7 @@ impl VideoFrame {
line_stride_or_size: LineStrideOrSize {
line_stride_in_bytes,
},
p_metadata: raw.p_metadata,
p_metadata,
timestamp: raw.timestamp,
}
}
Expand Down Expand Up @@ -709,13 +715,7 @@ impl AudioFrame {
let metadata = if raw.p_metadata.is_null() {
None
} else {
unsafe {
Some(
CStr::from_ptr(raw.p_metadata)
.to_string_lossy()
.into_owned(),
)
}
Some(unsafe { CString::from_raw(raw.p_metadata as *mut c_char) })
};

AudioFrame {
Expand All @@ -729,7 +729,7 @@ impl AudioFrame {
},
data,
channel_stride_in_bytes: unsafe { raw.__bindgen_anon_1.channel_stride_in_bytes },
metadata: metadata.map(|m| CString::new(m).unwrap()),
metadata,
timestamp: raw.timestamp,
}
}
Expand Down

0 comments on commit c9a90fb

Please sign in to comment.