@@ -26,6 +26,9 @@ zx_status_t zx_channel_create(
26
26
zx_status_t zx_handle_close (
27
27
zx_handle_t handle ZX_HANDLE_RELEASE);
28
28
29
+ ZX_HANDLE_ACQUIRE
30
+ zx_handle_t return_handle ();
31
+
29
32
void escape1 (zx_handle_t *in);
30
33
void escape2 (zx_handle_t in);
31
34
void (*escape3)(zx_handle_t ) = escape2;
@@ -117,7 +120,7 @@ void checkNoLeak06() {
117
120
118
121
void checkLeak01 (int tag) {
119
122
zx_handle_t sa, sb;
120
- if (zx_channel_create (0 , &sa, &sb)) // expected-note {{Handle allocated here }}
123
+ if (zx_channel_create (0 , &sa, &sb)) // expected-note {{Handle allocated through 2nd parameter }}
121
124
return ; // expected-note@-1 {{Assuming the condition is false}}
122
125
// expected-note@-2 {{Taking false branch}}
123
126
use1 (&sa);
@@ -129,9 +132,15 @@ void checkLeak01(int tag) {
129
132
zx_handle_close (sb);
130
133
}
131
134
135
+ void checkLeakFromReturn01 (int tag) {
136
+ zx_handle_t sa = return_handle (); // expected-note {{Function 'return_handle' returns an open handle}}
137
+ (void )sa;
138
+ } // expected-note {{Potential leak of handle}}
139
+ // expected-warning@-1 {{Potential leak of handle}}
140
+
132
141
void checkReportLeakOnOnePath (int tag) {
133
142
zx_handle_t sa, sb;
134
- if (zx_channel_create (0 , &sa, &sb)) // expected-note {{Handle allocated here }}
143
+ if (zx_channel_create (0 , &sa, &sb)) // expected-note {{Handle allocated through 2nd parameter }}
135
144
return ; // expected-note@-1 {{Assuming the condition is false}}
136
145
// expected-note@-2 {{Taking false branch}}
137
146
zx_handle_close (sb);
@@ -161,9 +170,9 @@ void checkReportLeakOnOnePath(int tag) {
161
170
void checkDoubleRelease01 (int tag) {
162
171
zx_handle_t sa, sb;
163
172
zx_channel_create (0 , &sa, &sb);
164
- // expected-note@-1 {{Handle allocated here }}
173
+ // expected-note@-1 {{Handle allocated through 2nd parameter }}
165
174
if (tag) // expected-note {{Assuming 'tag' is not equal to 0}}
166
- zx_handle_close (sa); // expected-note {{Handle released here }}
175
+ zx_handle_close (sa); // expected-note {{Handle released through 1st parameter }}
167
176
// expected-note@-2 {{Taking true branch}}
168
177
zx_handle_close (sa); // expected-warning {{Releasing a previously released handle}}
169
178
// expected-note@-1 {{Releasing a previously released handle}}
@@ -173,18 +182,18 @@ void checkDoubleRelease01(int tag) {
173
182
void checkUseAfterFree01 (int tag) {
174
183
zx_handle_t sa, sb;
175
184
zx_channel_create (0 , &sa, &sb);
176
- // expected-note@-1 {{Handle allocated here }}
177
- // expected-note@-2 {{Handle allocated here }}
185
+ // expected-note@-1 {{Handle allocated through 2nd parameter }}
186
+ // expected-note@-2 {{Handle allocated through 3rd parameter }}
178
187
// expected-note@+2 {{Taking true branch}}
179
188
// expected-note@+1 {{Taking false branch}}
180
189
if (tag) {
181
190
// expected-note@-1 {{Assuming 'tag' is not equal to 0}}
182
- zx_handle_close (sa); // expected-note {{Handle released here }}
191
+ zx_handle_close (sa); // expected-note {{Handle released through 1st parameter }}
183
192
use1 (&sa); // expected-warning {{Using a previously released handle}}
184
193
// expected-note@-1 {{Using a previously released handle}}
185
194
}
186
195
// expected-note@-6 {{Assuming 'tag' is 0}}
187
- zx_handle_close (sb); // expected-note {{Handle released here }}
196
+ zx_handle_close (sb); // expected-note {{Handle released through 1st parameter }}
188
197
use2 (sb); // expected-warning {{Using a previously released handle}}
189
198
// expected-note@-1 {{Using a previously released handle}}
190
199
}
0 commit comments