iolog: do stat() after fopen()
authorJens Axboe <axboe@fb.com>
Thu, 3 Jul 2014 21:32:07 +0000 (15:32 -0600)
committerJens Axboe <axboe@fb.com>
Thu, 3 Jul 2014 21:32:07 +0000 (15:32 -0600)
Avoid static checker complaining about a potential race here,
ordering doesn't matter to fio.

Signed-off-by: Jens Axboe <axboe@fb.com>
iolog.c

diff --git a/iolog.c b/iolog.c
index d08569fd40ebe9f217489bb843383f20bf6fa795..75ce623fe473f376df48806aa0719e4bd111167f 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -806,20 +806,21 @@ int iolog_file_inflate(const char *file)
        struct iolog_compress ic;
        z_stream stream;
        struct stat sb;
        struct iolog_compress ic;
        z_stream stream;
        struct stat sb;
-       size_t ret;
+       ssize_t ret;
        FILE *f;
 
        FILE *f;
 
-       if (stat(file, &sb) < 0) {
-               perror("stat");
-               return 1;
-       }
-
        f = fopen(file, "r");
        if (!f) {
                perror("fopen");
                return 1;
        }
 
        f = fopen(file, "r");
        if (!f) {
                perror("fopen");
                return 1;
        }
 
+       if (stat(file, &sb) < 0) {
+               fclose(f);
+               perror("stat");
+               return 1;
+       }
+
        ic.buf = malloc(sb.st_size);
        ic.len = sb.st_size;
        ic.nofree = 1;
        ic.buf = malloc(sb.st_size);
        ic.len = sb.st_size;
        ic.nofree = 1;