blob: 061c4daa9e0ab01fb9b2e2f9346becaa6678c939 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
namespace;
include rt;
// free quarantines the block. a stale alias still reads it, and freeing
// through the alias does nothing because the header already says free.
// unchecked so the analyzer doesn't reject the use after free.
unchecked fn main() {
let p = rt.new(4), q, r, i = 0, t, bad = 0;
p[0] = 111; p[1] = 222; p[2] = 333; p[3] = 444;
q = p;
r = p + 2;
rt.free(p);
while (i < 400) { t = rt.new(4); t[0] = 999; t[1] = 888; t[2] = 777; t[3] = 666; i++; }
if (q[0] != 111 || q[1] != 222 || r[0] != 333 || r[1] != 444) bad = 1;
rt.free(q);
if (q[0] != 111 || q[1] != 222) bad = 2;
rt.gc(); // q still points at the block, so the sweep must not reuse it
if (q[0] != 111 || r[0] != 333) bad = 3;
p = 0; q = 0; r = 0; t = 0;
rt.scrub();
rt.gc();
t = rt.new(4);
t[0] = 1234;
rt.put_n(bad); rt.put_c(' ');
rt.put_n(t[0]); rt.put_c(10);
rt.free(t);
return 0;
}
|