One Ownership Model, Four APIs
Malloc claims a free block. Free makes it reusable. Realloc transfers ownership after success. Calloc clears the requested bytes after allocation.
1 / 5
Malloc claims a free block. Free makes it reusable. Realloc transfers ownership after success. Calloc clears the requested bytes after allocation.
A:32 live, B:64 live. Free A, then request 20.
A is reused and retains capacity 32. B remains untouched.
A is live; request SIZE_MAX.
Reject before heap mutation. Return NULL; A remains used and its bytes unchanged.
A zero-size custom realloc instead deliberately frees A.
Adjacent free payloads 32 and 64, header H.
Merged capacity: 32 + H + 64.
Check physical adjacency; list neighbors may have padding or other storage between them.
Does calloc need to clear a reused block?
Yes: free changes eligibility, not contents. Zero all requested bytes even if the capacity is larger.
The capstone requires reuse; splitting and coalescing are optional extensions.