Skip to content

Commit

Permalink
fix: zero-out allocated memory
Browse files Browse the repository at this point in the history
Mac seems to do that by default, but some operating systems are not as
kind

Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Sep 19, 2024
1 parent 0ca61f0 commit f8e20df
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::ops::{BitOrAssign, Deref, DerefMut, Shl};
use core::ptr::{copy_nonoverlapping, null, NonNull};
use core::slice;

use std::alloc::alloc;
use std::alloc::{alloc, alloc_zeroed};
use std::collections::HashSet;
use std::sync::{Arc, LazyLock};

Expand Down Expand Up @@ -402,7 +402,9 @@ fn lower(
let align = align_of(&ty);
let layout = Layout::from_size_align(size, align)
.context("failed to construct list memory layout")?;
let start = unsafe { alloc(layout) }.cast::<c_void>();
trace!(?layout, "allocating list");
let start = unsafe { alloc_zeroed(layout) }.cast::<c_void>();
ensure!(!start.is_null(), "failed to allocate list");
let mut data = start;
for (i, val) in vals.into_iter().enumerate() {
let dst = NonNull::new(data)
Expand Down

0 comments on commit f8e20df

Please sign in to comment.