iolog: Fix write_iolog_close()
authorDamien Le Moal <damien.lemoal@wdc.com>
Fri, 8 May 2020 07:56:39 +0000 (16:56 +0900)
committerJens Axboe <axboe@kernel.dk>
Fri, 15 May 2020 13:41:32 +0000 (07:41 -0600)
If the init_iolog() call from backend.c thread_main() fails (e.g. wrong
file path given), td->iolog_f is not set but write_iolog_close() is
still called from thread_main() error processing. This causes a seg
fault and unclean termination of fio. Fix this by changing
write_iolog_close() to do nothing if td->iolog_f is NULL.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
iolog.c

diff --git a/iolog.c b/iolog.c
index 917a446cbc5e811356d9197543cb7940088c9409..4a79fc4667fc13eff4c62b9206a0dfefe0a5dfd4 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -342,6 +342,9 @@ void trim_io_piece(const struct io_u *io_u)
 
 void write_iolog_close(struct thread_data *td)
 {
 
 void write_iolog_close(struct thread_data *td)
 {
+       if (!td->iolog_f)
+               return;
+
        fflush(td->iolog_f);
        fclose(td->iolog_f);
        free(td->iolog_buf);
        fflush(td->iolog_f);
        fclose(td->iolog_f);
        free(td->iolog_buf);