]>
Commit | Line | Data |
---|---|---|
885824d3 | 1 | extern /*@only@*/ char *string_copyext (char *s) ; |
2 | ||
3 | void f (void) | |
4 | { | |
5 | char *s; | |
6 | ||
7 | if (3 < 4) | |
8 | { | |
9 | s = string_copyext ("asdf"); | |
10 | free (s); | |
11 | } | |
12 | } | |
13 | ||
14 | ||
15 | /*@only@*/ char *string_copy (char *s) | |
16 | { | |
17 | return s; /* 1. returns temp as only! */ | |
18 | } | |
19 | ||
20 | /*@only@*/ char *copy_string1 (char *s) | |
21 | { | |
22 | return string_copy (s); /* okay */ | |
23 | } | |
24 | ||
25 | /*@only@*/ char *copy_string2 (char *s) | |
26 | { | |
27 | return string_copyext (s); /* okay */ | |
28 | } | |
29 | ||
30 | void string_free1 (char *s) | |
31 | { | |
32 | free (s); /* 2. unqualified as only */ | |
33 | } | |
34 | ||
35 | void string_free2 (/*@only@*/ char *s) | |
36 | { | |
37 | free (s); | |
38 | } | |
39 | ||
40 | void string_free3 (/*@only@*/ char *s) | |
41 | { | |
42 | char *t = string_copy (s); | |
43 | string_free2 (s); | |
44 | *t = 'a'; | |
45 | } /* 3. bad, t not released */ | |
46 | ||
47 | void string_free4 (/*@only@*/ char *s) | |
48 | { | |
49 | char *t; | |
50 | int i; | |
51 | ||
52 | for (i = 0; i < 3; i++) | |
53 | { | |
54 | t = string_copy (s); | |
55 | *t = 'a'; | |
56 | free (t); | |
57 | } | |
58 | ||
59 | free (s); | |
60 | } /* okay */ | |
61 |