log: fix use-after-free
authorJens Axboe <axboe@fb.com>
Wed, 2 Jul 2014 19:36:34 +0000 (13:36 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 2 Jul 2014 19:36:34 +0000 (13:36 -0600)
Introduced in commit cb7e0ace739c.

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

index 95a7572d86bdf06798428ebc635e7622fd3bc32a..448fc5981ada3f1724df6982b876554ab22dd10c 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2047,6 +2047,7 @@ int fio_backend(void)
                                struct io_log *log = agg_io_log[i];
 
                                __finish_log(log);
+                               free_log(log);
                        }
                }
        }
diff --git a/iolog.c b/iolog.c
index a8bead11292c824eb3371f4f2c3e7a8545108cf7..96afec665c73a81c7c37286b77e2b3143e38be53 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -581,7 +581,7 @@ static void clear_file_buffer(void *buf)
 }
 #endif
 
-static void free_log(struct io_log *log)
+void free_log(struct io_log *log)
 {
        free(log->log);
        free(log->filename);
@@ -623,7 +623,6 @@ void __finish_log(struct io_log *log)
 
        fclose(f);
        clear_file_buffer(buf);
-       free_log(log);
 }
 
 static int finish_log(struct thread_data *td, struct io_log *log, int trylock)
@@ -636,11 +635,11 @@ static int finish_log(struct thread_data *td, struct io_log *log, int trylock)
 
        if (td->client_type == FIO_CLIENT_TYPE_GUI) {
                fio_send_iolog(td, log, log->filename);
-               free_log(log);
        } else
                __finish_log(log);
 
        fio_unlock_file(log->filename);
+       free_log(log);
        return 0;
 }
 
diff --git a/iolog.h b/iolog.h
index 2c9b2b29cc7c5e6527ac3a251aa99a9394df59dd..f97d91f792f717f2d4286e2ac9374939e832ba8f 100644 (file)
--- a/iolog.h
+++ b/iolog.h
@@ -171,6 +171,7 @@ extern void init_disk_util(struct thread_data *);
 extern void update_rusage_stat(struct thread_data *);
 extern void setup_log(struct io_log **, unsigned long, int, int, const char *);
 extern void __finish_log(struct io_log *);
+extern void free_log(struct io_log *);
 extern struct io_log *agg_io_log[DDIR_RWDIR_CNT];
 extern int write_bw_log;
 extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);