fio: fix job clone mem leak
authorChristian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Wed, 19 Feb 2014 18:42:41 +0000 (10:42 -0800)
committerJens Axboe <axboe@fb.com>
Wed, 19 Feb 2014 18:42:41 +0000 (10:42 -0800)
In the loop to create clones at the bottom of add_job the function
get_new_job clones the thread_data, just to occaisonally get the
allocated pointers for filename and files overwritten a few lines later.

The dup files also duplicates the name strings so the references to
these are lost by the setting to null.

This patch fixes takes care of that and frees the memory before
discarding the pointers (found via valgrind).

Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
init.c

diff --git a/init.c b/init.c
index fa1df8e7e760eac9c7a37f7d8afaa3ff9614c6cd..469e73dc433c4b9a020d6fb1bc5d2c17aa98960f 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1118,10 +1118,21 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                td_new->o.new_group = 0;
 
                if (file_alloced) {
                td_new->o.new_group = 0;
 
                if (file_alloced) {
-                       td_new->o.filename = NULL;
                        td_new->files_index = 0;
                        td_new->files_size = 0;
                        td_new->files_index = 0;
                        td_new->files_size = 0;
-                       td_new->files = NULL;
+                       if (td_new->files) {
+                               struct fio_file *f;
+                               for_each_file(td_new, f, i) {
+                                       if (f->file_name)
+                                               free(f->file_name);
+                                       free(f);
+                               }
+                               td_new->files = NULL;
+                       }
+                       if (td_new->o.filename) {
+                               free(td_new->o.filename);
+                               td_new->o.filename = NULL;
+                       }
                }
 
                job_add_num = numjobs - 1;
                }
 
                job_add_num = numjobs - 1;