| 1 |
typedef struct FILE FILE; |
| 2 |
|
| 3 |
FILE* fopen (const char*, const char*); |
| 4 |
int fclose (FILE*); |
| 5 |
int fprintf (FILE *, const char *, ...); |
| 6 |
|
| 7 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 8 |
|
| 9 |
|
| 10 |
void |
| 11 |
test_1 (void) |
| 12 |
{ |
| 13 |
int i; |
| 14 |
|
| 15 |
for (i = 0; i < 2; ++i) { |
| 16 |
FILE *fp = fopen ("/tmp/test", "w"); |
| 17 |
fprintf (fp, "hello:%s ", "world"); |
| 18 |
fclose (fp); /* { dg-bogus "double 'fclose'" } */ |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
void |
| 23 |
test_2 (void) |
| 24 |
{ |
| 25 |
int i; |
| 26 |
|
| 27 |
for (i = 0; i < 2; ++i) { |
| 28 |
FILE *fp = fopen ("/tmp/test", "w"); |
| 29 |
fprintf (fp, "hello"); |
| 30 |
} |
| 31 |
} /* { dg-warning "leak of FILE 'fp'" } */ |
| 32 |
|
| 33 |
FILE *fp3; |
| 34 |
|
| 35 |
void |
| 36 |
test_3 (FILE **fpp) |
| 37 |
{ |
| 38 |
int i; |
| 39 |
|
| 40 |
for (i = 0; i < 2; ++i) { |
| 41 |
*fpp = fopen ("/tmp/test", "w"); |
| 42 |
fprintf (*fpp, "hello"); |
| 43 |
fclose (*fpp); /* { dg-bogus "double 'fclose'" } */ |
| 44 |
*fpp = NULL; |
| 45 |
} |
| 46 |
} |