]>
Commit | Line | Data |
---|---|---|
885824d3 | 1 | /*@-paramuse@*/ |
2 | ||
3 | /*@only@*/ int *globonly; | |
4 | /*@shared@*/ int *globshared1; | |
5 | /*@shared@*/ int *globshared2; | |
6 | /*@only@*/ int *zonly; | |
7 | ||
8 | void f(/*@only@*/ int *x, /*@temp@*/ int *y, /*@shared@*/ int *z) | |
9 | { | |
10 | *x = 3; | |
11 | if (3 > *x) | |
12 | return; /* 1. bad x not released */ | |
13 | } /* 2. bad x not released */ | |
14 | ||
15 | int f2(/*@temp@*/ int *x, /*@only@*/ int *y) | |
16 | { | |
17 | *x = 3; | |
18 | *y = 6; | |
19 | return 3; /* 3. bad y not released */ | |
20 | } | |
21 | ||
22 | void f3(/*@only@*/ int *x) | |
23 | { | |
24 | globshared1 = x; /* 4. bad shared globshared1 <- only x */ | |
80ee600a | 25 | } /* 5. only not released */ |
885824d3 | 26 | |
27 | void f4(/*@only@*/ int *x) | |
28 | { | |
29 | zonly = x; /* 6. bad - didn't release zonly */ | |
30 | } /* okay */ | |
31 | ||
32 | int g(int *imp) | |
33 | { | |
34 | int x = 3; | |
35 | int *y = malloc(sizeof(int)); | |
36 | int *y2 = malloc(sizeof(int)); | |
37 | int *y3 = malloc(sizeof(int)); | |
38 | ||
39 | if (y2) *y2 = 3; | |
40 | ||
41 | f3 (imp); /* 7. bad if +memimplicit --- unqualified as only */ | |
42 | *imp = 5; /* 8. uses released */ | |
43 | ||
44 | (void) f(&x, /* 9, 10. pass immediate as only, only parameter aliased */ | |
45 | &x, | |
46 | globshared1); | |
47 | ||
48 | (void) f2 (y3, y3); /* 11-15. --- 2 * null passed as nonnull, 2 * not completely def | |
49 | only parameter y3 aliased */ | |
50 | *y3 = 6; /* 16, 17. bad --- y3 was released, null */ | |
51 | (void) f(y, globshared1, globshared1); /* 18, 19. null as non-null, y not completely def */ | |
52 | (void) f(globshared1, /* 20. pass shared as only */ | |
53 | globshared2, | |
54 | globshared2); | |
55 | ||
56 | free (globshared2); /* 21. bad --- free's shared! (pass shared as only) */ | |
57 | free (globonly); | |
58 | ||
59 | return *y; /* 22-25. y used after release, possible null, | |
60 | locally allocated y2 not released, | |
61 | globonly is released */ | |
62 | } | |
63 | ||
64 | ||
65 |