[PATCH] Be nicer about cleaning up allocated memory
authorJens Axboe <jens.axboe@oracle.com>
Fri, 20 Oct 2006 11:54:47 +0000 (13:54 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 20 Oct 2006 11:54:47 +0000 (13:54 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
filesetup.c
fio.c
log.c
stat.c

index d6df4f9fccb7b699c7e5dcfe292bbd4b6d65d8ac..2e81a1d10c88320e4396d625e99be1e9d9a04a9f 100644 (file)
@@ -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 5673d9ef690cc8e8c6d6bbe31dccc5fb3cc937ba..bdfbd827806502d5ee85e721b753d4dcb3683748 100644 (file)
--- 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 51eaee6ecae085e6bc71184148ba26bf8574c1e1..91ac0830582625af31a8c78c730ee78ffc53ccd8 100644 (file)
--- 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 718a8ab2acc1ee65618f132c3efabb9dc6ce7aef..fc0abe0a82b573742d781fa6cde65fc768f9d105 100644 (file)
--- 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,