Skip to contentSkip to conversation

fio: fix job clone mem leak

PATCH In review [email protected] 1 participant 1 message Feb 20, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/9 fio: fix job clone mem leak

*Resend with hopefully non mangled patches*
References: <[email protected]>
Content-Disposition: inline; filename=fio-fix-cloneleak.diff

From: Christian Ehrhardt <[email protected]>

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).

---

[diffstat]

 init.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

[diff]

init.c +13 -2
@@ -1118,10 +1118,21 @@ static int add_job(struct thread_data *t
 		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;