From 455a50fa14f2663c388abc1138623b9c4405345b Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Wed, 19 Feb 2014 10:42:41 -0800 Subject: [PATCH] fio: fix job clone mem leak 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 Signed-off-by: Jens Axboe --- init.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/init.c b/init.c index fa1df8e7..469e73dc 100644 --- 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.filename = NULL; 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; -- 2.25.1