From b4a6a59a939f0e6554632de311e7d1d1b7633ccf Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 20 Oct 2006 13:54:47 +0200 Subject: [PATCH] [PATCH] Be nicer about cleaning up allocated memory Signed-off-by: Jens Axboe --- filesetup.c | 6 ++++++ fio.c | 17 +++++++++++++---- log.c | 8 ++++++-- stat.c | 12 +++++++++++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/filesetup.c b/filesetup.c index d6df4f9f..2e81a1d1 100644 --- a/filesetup.c +++ b/filesetup.c @@ -406,6 +406,8 @@ void close_files(struct thread_data *td) if (f->fd != -1) { if (td->unlink && td->filetype == FIO_TYPE_FILE) unlink(f->file_name); + free(f->file_name); + f->file_name = NULL; close(f->fd); f->fd = -1; } @@ -414,4 +416,8 @@ void close_files(struct thread_data *td) f->mmap = NULL; } } + + free(td->files); + td->files = NULL; + td->nr_files = 0; } diff --git a/fio.c b/fio.c index 5673d9ef..bdfbd827 100644 --- a/fio.c +++ b/fio.c @@ -586,8 +586,13 @@ static void *thread_main(void *data) if (init_random_state(td)) goto err; - if (td->ioscheduler && switch_ioscheduler(td)) - goto err; + if (td->ioscheduler) { + int ret = switch_ioscheduler(td); + + free(td->ioscheduler); + if (ret) + goto err; + } td_set_runstate(td, TD_INITIALIZED); fio_sem_up(&startup_sem); @@ -598,8 +603,10 @@ static void *thread_main(void *data) gettimeofday(&td->epoch, NULL); - if (td->exec_prerun) + if (td->exec_prerun) { system(td->exec_prerun); + free(td->exec_prerun); + } while (td->loops--) { getrusage(RUSAGE_SELF, &td->ru_start); @@ -648,8 +655,10 @@ static void *thread_main(void *data) finish_log(td, td->clat_log, "clat"); if (td->write_iolog) write_iolog_close(td); - if (td->exec_postrun) + if (td->exec_postrun) { system(td->exec_postrun); + free(td->exec_postrun); + } if (exitall_on_terminate) terminate_threads(td->groupid); diff --git a/log.c b/log.c index 51eaee6e..91ac0830 100644 --- a/log.c +++ b/log.c @@ -170,11 +170,15 @@ static int init_iolog_write(struct thread_data *td) int init_iolog(struct thread_data *td) { + int ret = 0; + if (td->read_iolog) - return init_iolog_read(td); + ret = init_iolog_read(td); else if (td->write_iolog) - return init_iolog_write(td); + ret = init_iolog_write(td); + free(td->iolog_file); + td->iolog_file = NULL; return 0; } diff --git a/stat.c b/stat.c index 718a8ab2..fc0abe0a 100644 --- a/stat.c +++ b/stat.c @@ -300,7 +300,7 @@ static void show_group_stats(struct group_run_stats *rs, int id) static void show_disk_util(void) { struct disk_util_stat *dus; - struct list_head *entry; + struct list_head *entry, *next; struct disk_util *du; double util; @@ -316,6 +316,16 @@ static void show_disk_util(void) fprintf(f_out, " %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, in_queue=%u, util=%3.2f%%\n", du->name, dus->ios[0], dus->ios[1], dus->merges[0], dus->merges[1], dus->ticks[0], dus->ticks[1], dus->time_in_queue, util); } + + /* + * now free the list + */ + list_for_each_safe(entry, next, &disk_list) { + list_del(entry); + du = list_entry(entry, struct disk_util, list); + free(du->name); + free(du); + } } static void show_ddir_status(struct thread_data *td, struct group_run_stats *rs, -- 2.25.1