blob: 54a1a3ca001c643074492292de93359dc6cdf7a0 [file] [log] [blame]
sewardjcbdddcf2005-03-10 23:23:45 +00001#include <stdlib.h>
2#include "../memcheck.h"
3
4struct n {
5 struct n *l;
6 struct n *r;
7};
8
9struct n *mk(struct n *l, struct n *r)
10{
11 struct n *n = malloc(sizeof(*n));
12 n->l = l;
13 n->r = r;
14
15 return n;
16}
17
18static struct n *mkcycle()
19{
20 register struct n *a, *b, *c;
21
22 a = mk(0,0);
23 b = mk(a,0);
24 c = mk(b,0);
25 a->l = c;
26
27 return a;
28}
29
30int main()
31{
32
33 struct n *volatile c1, *volatile c2;
34
35 /* two simple cycles */
36 c1 = mkcycle();
37 c2 = mkcycle();
38
39 c1 = c2 = 0;
40
41 //VALGRIND_DO_LEAK_CHECK;
42
43 /* one cycle linked to another */
44 c1 = mkcycle();
45 c2 = mkcycle();
46
47 /* This is to make sure we end up merging cliques; see
48 mac_leakcheck.c */
49 if (c1 < c2)
50 c2->r = c1;
51 else
52 c1->r = c2;
53
54 c1 = c2 = 0;
55
56 //VALGRIND_DO_LEAK_CHECK;
57
58 /* two linked cycles */
59 c1 = mkcycle();
60 c2 = mkcycle();
61
62 c1->r = c2;
63 c2->r = c1;
64
65 c1 = c2 = 0;
66
67 VALGRIND_DO_LEAK_CHECK;
68
69 return 0;
70}