pub unsafe fn free(ptr: *mut u8) -> Result<(), DeallocationError>Expand description
This function is the counterpart to crate::alloc.
Every pointer produced by crate::alloc or crate::realloc must eventually be
released with this function or crate::realloc. Unlike C’s free, passing a null
pointer returns an error instead of being a no-op.
§Errors
An error is returned if a safety check fails.
§Safety
Only pointers produced by crate::alloc or crate::realloc may be freed using
this function; passing any other pointer causes undefined behaviour. The safety
checks are best-effort: any error other than NullPtr indicates that undefined
behaviour has already occurred, and the checks are performed non-atomically, so
concurrent misuse from another thread may go undetected. Unless ptr is misaligned
or null, this function will dereference it.