From f8e20df67ba2dd5e8718826e5330aac7dd44586d Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 19 Sep 2024 21:42:21 +0200 Subject: [PATCH] fix: zero-out allocated memory Mac seems to do that by default, but some operating systems are not as kind Signed-off-by: Roman Volosatovs --- crates/sys/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/sys/src/lib.rs b/crates/sys/src/lib.rs index c8d8d69..139fe0e 100644 --- a/crates/sys/src/lib.rs +++ b/crates/sys/src/lib.rs @@ -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}; @@ -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::(); + trace!(?layout, "allocating list"); + let start = unsafe { alloc_zeroed(layout) }.cast::(); + 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)