Q291FreeSystemVerilog
Reject invalid deallocation
Interview prompt
Question
Detect zero-sized, double, partial, and otherwise invalid deallocation requests before they can corrupt the free list.
Starting point
Question code
function bit alloc_checked(
int unsigned size,
output int unsigned addr
);
function bit dealloc_checked(
int unsigned addr,
int unsigned size
);Reviewed example
Trace one case
Input
recorded allocation: base=0x1000,size=0x20; dealloc_checked(0x1000,0x10)Expected output
reject partial deallocation; allocation map and free list unchangedThe base matches but the size does not, so exact allocation metadata prevents silent range corruption.
What to cover
Requirements
- Route successful allocations through a wrapper that records size by returned base address.
- Require an exact base and size match on deallocation.
- Leave allocator state unchanged on failure.
- Coalesce the returned interval after successful validation.

