aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/quarantine.zc
blob: 5e3e188a589387600fe75a8339b2ac002f5f9377 (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
// 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 = 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;
	free(p);
	while (i < 400) { t = 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;
	free(q);
	if (q[0] != 111 || q[1] != 222) bad = 2;
	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;
	scrub();
	gc();
	t = new(4);
	t[0] = 1234;
	put_n(bad); put_c(' ');
	put_n(t[0]); put_c(10);
	free(t);
	return 0;
}