Skip to content

Commit d92b523

Browse files
committed
Return OutOfMemory from alloc_dynamic_table_elements on failure
This is more correct and also `ensure!` will attempt to allocate, which trips up the OOM test framework.
1 parent 4bb429a commit d92b523

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/wasmtime/src/runtime/vm/table.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ unsafe fn alloc_dynamic_table_elements<T>(len: usize) -> Result<Vec<Option<T>>>
314314
let layout = Layout::from_size_align(size, align)?;
315315

316316
let ptr = unsafe { alloc::alloc::alloc_zeroed(layout) };
317-
ensure!(!ptr.is_null(), "failed to allocate memory for table");
317+
if ptr.is_null() {
318+
return Err(OutOfMemory::new(size).into());
319+
}
318320

319321
let elems = unsafe { Vec::<Option<T>>::from_raw_parts(ptr.cast(), len, len) };
320322
debug_assert!(elems.iter().all(|e| e.is_none()));

0 commit comments

Comments
 (0)