raz / test / run / HeapDebugFree.raz

20 lines · 471 B · raw · history · last change 264716cb

1module HeapDebugFree;
2(* in debug mode, a write to a freed block is found when the block
3 leaves the quarantine, 1,024 frees later, and stops the program *)
4import Heap, Mem;
5import SYSTEM;
6
7proc main*;
8var p, q: ^U8; i: INT;
9begin
10 Heap.debug(true);
11 p := Mem.alloc(Heap.heap, 20, 8);
12 Mem.free(Heap.heap, p);
13 p[3] := 1;
14 for i := 0 to 1024 do
15 q := Mem.alloc(Heap.heap, 20, 8);
16 Mem.free(Heap.heap, q);
17 end;
18end;
19
20end HeapDebugFree.