B6012: an enclave's cell freed twice
Catalog status: active. Default severity: error. Stable name: double-free. Family: Ownership and finalization.
A program's proof enclaves take their cells from a checking allocator, which records whether each cell is live, so that a mistake in what is not proved of them is a failed check rather than a corruption. Freeing a cell that was already freed, through another pointer that designated it, is a failed run-time check: the program stops at the second Unchecked_Deallocation.
Example (Vada)
procedure Drop (S : in out Stack) is
First : Node_Ptr := S.Top;
Again : Node_Ptr := S.Top;
begin
Free (First);
Free (Again); -- the same cell
...What to do (Vada)
Free each cell once, through one pointer, after every other pointer to it has been moved off it or set to null. The heap engine proves this of an enclave whose types keep footprints (B5118); in what it does not prove, the checking allocator finds the paths that break it.
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See ownership and finalization, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.