From fd771971384a5ff2c59921617f3d59e26490ec06 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 3 Jul 2014 15:32:07 -0600 Subject: [PATCH] iolog: do stat() after fopen() Avoid static checker complaining about a potential race here, ordering doesn't matter to fio. Signed-off-by: Jens Axboe --- iolog.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iolog.c b/iolog.c index d08569fd..75ce623f 100644 --- 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; - size_t ret; + ssize_t ret; FILE *f; - if (stat(file, &sb) < 0) { - perror("stat"); - 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; -- 2.25.1