From e711df54082b5d2d739e9ee3e46a2bc23b1b3c7c Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 19 Aug 2020 13:02:42 -0600 Subject: [PATCH] file: provider fio_file_free() helper Since we have two spots, provide a helper to do the freeing. Signed-off-by: Jens Axboe --- file.h | 1 + filesetup.c | 28 ++++++++++++++-------------- init.c | 15 ++------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/file.h b/file.h index 5e2ef998..493ec04a 100644 --- a/file.h +++ b/file.h @@ -231,5 +231,6 @@ extern void fio_file_reset(struct thread_data *, struct fio_file *); extern bool fio_files_done(struct thread_data *); extern bool exists_and_not_regfile(const char *); extern int fio_set_directio(struct thread_data *, struct fio_file *); +extern void fio_file_free(struct fio_file *); #endif diff --git a/filesetup.c b/filesetup.c index a1c60445..d382fa24 100644 --- a/filesetup.c +++ b/filesetup.c @@ -1445,6 +1445,19 @@ void close_files(struct thread_data *td) } } +void fio_file_free(struct fio_file *f) +{ + if (fio_file_axmap(f)) + axmap_free(f->io_axmap); + if (!fio_file_smalloc(f)) { + free(f->file_name); + free(f); + } else { + sfree(f->file_name); + sfree(f); + } +} + void close_and_free_files(struct thread_data *td) { struct fio_file *f; @@ -1469,20 +1482,7 @@ void close_and_free_files(struct thread_data *td) } zbd_close_file(f); - - if (!fio_file_smalloc(f)) - free(f->file_name); - else - sfree(f->file_name); - f->file_name = NULL; - if (fio_file_axmap(f)) { - axmap_free(f->io_axmap); - f->io_axmap = NULL; - } - if (!fio_file_smalloc(f)) - free(f); - else - sfree(f); + fio_file_free(f); } td->o.filename = NULL; diff --git a/init.c b/init.c index 3073c2a0..491b46e6 100644 --- a/init.c +++ b/init.c @@ -1735,19 +1735,8 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, if (file_alloced) { if (td_new->files) { struct fio_file *f; - for_each_file(td_new, f, i) { - bool use_smalloc = fio_file_smalloc(f); - if (f->file_name) { - if (use_smalloc) - sfree(f->file_name); - else - free(f->file_name); - } - if (use_smalloc) - sfree(f); - else - free(f); - } + for_each_file(td_new, f, i) + fio_file_free(f); free(td_new->files); td_new->files = NULL; } -- 2.25.1