From ebfc9c1c4ebf294822da14ea128b6799cc712652 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 8 Oct 2023 11:24:55 +0200 Subject: [PATCH] Zero memory on allocation --- kernel/src/allocator.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/src/allocator.rs b/kernel/src/allocator.rs index 5329844e..bd225bfa 100644 --- a/kernel/src/allocator.rs +++ b/kernel/src/allocator.rs @@ -150,7 +150,8 @@ impl Heap { #[cfg(debug_assertions)] trace!("Allocating {:?}", ptr); } - // FIXME: zero out memory to prevent leaking data + + unsafe { core::ptr::write_bytes(ptr, 0, size) }; assert!(ptr.is_aligned_to(alignment)); NonNull::new(ptr) @@ -168,6 +169,7 @@ impl Heap { self.bitmap_set_range(start, size, false); self.allocated_chunks -= size; // FIXME: zero out memory to prevent leaking data + // REPLY: When we zero on alloc, do we really need it? } /// Finds first hole that can fit an allocation of `size` chunks, returns the start of the