Check for allocation failure in alloc_aligned

This commit is contained in:
Michael Pfaff 2022-11-07 10:10:00 -05:00
parent aba7d5148a
commit 97464fb262
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
1 changed files with 5 additions and 1 deletions

View File

@ -138,7 +138,11 @@ pub unsafe fn alloc_aligned_box_slice<T, const ALIGN: usize>(len: usize) -> Box<
#[inline(always)]
pub unsafe fn alloc_aligned(len: usize, align: usize) -> *mut u8 {
let layout = std::alloc::Layout::from_size_align_unchecked(len, align);
std::alloc::alloc(layout)
let ptr = std::alloc::alloc(layout);
if ptr.is_null() {
std::alloc::handle_alloc_error(layout);
}
ptr
}
#[macro_export]