diff --git a/rustler/src/alloc.rs b/rustler/src/alloc.rs index 799841ac..3478dded 100644 --- a/rustler/src/alloc.rs +++ b/rustler/src/alloc.rs @@ -16,8 +16,7 @@ unsafe impl GlobalAlloc for EnifAllocator { if layout.align() > MAX_ALIGN { // overallocate and store the original pointer in memory immediately before the aligned // section - let padded = layout.pad_to_align(); - let total_size = SIZEOF_USIZE + padded.size(); + let total_size = SIZEOF_USIZE + layout.size() + layout.align() - 1; let ptr = rustler_sys::enif_alloc(total_size) as *mut u8; let ptr1 = ptr.wrapping_add(SIZEOF_USIZE);