blob: 7570564a3e5af9f5f82454694a300264f76f3e28 [file] [log] [blame]
sewardjcbdddcf2005-03-10 23:23:45 +00001#include <stdio.h>
2#include <stdlib.h>
3#include "../memcheck.h"
4
5struct foo {
6 struct foo *l, *r;
7};
8
9struct foo *mk(struct foo *l, struct foo *r)
10{
11 struct foo *f = malloc(sizeof(*f));
12 f->l = l;
13 f->r = r;
14
15 return f;
16}
17
18int main()
19{
20 struct foo *volatile a, *volatile b, *volatile c;
21
22 b = mk(mk(0, 0), 0);
23
24 /* Partially leaked tree structure */
25 a = mk(mk(mk(mk(mk(0, 0), 0), mk(mk(0, 0), b)), mk(0, 0)), mk(0,0));
26
27 a = NULL;
28
29 VALGRIND_DO_LEAK_CHECK;
30
31 b = NULL; /* now leak old b */
32
33 /* Completely leaked, but part of the structure is shared */
34 b = mk(0,0);
35 b->l = b;
36 b->r = b;
37
38 a = mk(b,b);
39 c = mk(b,b);
40
41 a = b = c = 0;
42
43 VALGRIND_DO_LEAK_CHECK;
44
45 return 0;
46}