From 97464fb262554059da0a3842d2d5c4c29dcc75f5 Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Mon, 7 Nov 2022 10:10:00 -0500 Subject: [PATCH] Check for allocation failure in alloc_aligned --- src/util.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index b29d387..fc7ef3c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -138,7 +138,11 @@ pub unsafe fn alloc_aligned_box_slice(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]