Skip to main content

dealloc_for_layout

Function dealloc_for_layout 

Source
pub unsafe fn dealloc_for_layout(ptr: PtrMut, layout: Layout)
Expand description

Deallocates memory for a layout, correctly handling zero-sized types.

For ZSTs (zero-sized types), this is a no-op since no memory was actually allocated. This avoids undefined behavior since alloc::alloc::dealloc with a zero-sized layout is UB.

§Safety

  • For non-ZST layouts, ptr must have been allocated by alloc_for_layout (or alloc::alloc::alloc) with the same layout.
  • ptr must not have been deallocated already.
  • For ZST layouts, ptr is ignored (should be the dangling pointer from alloc_for_layout, but this isn’t checked).