| 1 | module 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 *) |
| 4 | import Heap, Mem; |
| 5 | import SYSTEM; |
| 6 | |
| 7 | proc main*; |
| 8 | var p, q: ^U8; i: INT; |
| 9 | begin |
| 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; |
| 18 | end; |
| 19 | |
| 20 | end HeapDebugFree. |