1 typedef struct FILE FILE;
3 FILE* fopen (const char*, const char*);
6 int fseek (FILE *, long int, int);
9 test_1 (const char *path
)
11 FILE *f
= fopen (path
, "r"); /* { dg-message "opened here" } */
15 fclose (f
); /* { dg-message "\\(4\\) \\.\\.\\.to here" "to here" } */
16 /* { dg-message "\\(5\\) first 'fclose' here" "first fclose" { target *-*-* } .-1 } */
17 fclose (f
); /* { dg-warning "double 'fclose' of FILE 'f' \\\[CWE-1341\\\]" "warning" } */
18 /* { dg-message "second 'fclose' here; first 'fclose' was at \\(5\\)" "second fclose" { target *-*-* } .-1 } */
21 /* Swallow -Wuse-after-free issued for the same problem
22 { dg-prune-output "-Wuse-after-free" } */
25 test_2 (const char *src
, const char *dst
)
27 FILE *f_in
= fopen (src
, "r"); /* { dg-message "\\(1\\) opened here" } */
31 FILE *f_out
= fopen (src
, "w");
33 return; /* { dg-warning "leak of FILE 'f_in'" "warning" } */
34 /* { dg-message "\\(7\\) 'f_in' leaks here; was opened at \\(1\\)" "event" { target *-*-* } .-1 } */
41 test_3 (const char *path
)
43 FILE *f
= fopen (path
, "r"); /* { dg-message "opened here" } */
44 return; /* { dg-warning "leak of FILE 'f'" } */
48 test_4 (const char *path
)
50 FILE *f
= fopen (path
, "r"); /* { dg-message "opened here" } */
52 /* Ensure we know about common fns that are known to not close the
53 file (e.g. "fseek"). */
54 fseek (f
, 1024, SEEK_SET
);
56 return; /* { dg-warning "leak of FILE 'f'" } */
60 test_5 (const char *path
)
62 FILE *f
= fopen (path
, "r"); /* { dg-message "opened here" } */
63 return; /* { dg-warning "leak of FILE 'f'" } */