From caf1fdaafe4f4e2c64caacb86960e4fc831aded3 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 18 Mar 2014 15:51:10 +0100 Subject: partial_sim: Fix filename memory corruption when using -j --- src/partial_sim.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/partial_sim.c') diff --git a/src/partial_sim.c b/src/partial_sim.c index 5b05218f..559d62cf 100644 --- a/src/partial_sim.c +++ b/src/partial_sim.c @@ -339,6 +339,11 @@ static void run_job(void *vwargs, int cookie) orientation = random_quaternion(qargs->rngs[cookie]); crystal_set_cell(cr, cell_rotate(qargs->cell, orientation)); + wargs->image.filename = malloc(256); + if ( wargs->image.filename == NULL ) { + ERROR("Failed to allocate filename.\n"); + return; + } if ( qargs->image_prefix != NULL ) { snprintf(wargs->image.filename, 255, "%s%i.h5", qargs->image_prefix, wargs->n); @@ -393,6 +398,7 @@ static void finalise_job(void *vqargs, void *vwargs) qargs->n_done++; progress_bar(qargs->n_done, qargs->n_to_do, "Simulating"); + free(wargs->image.filename); crystal_free(wargs->crystal); free(wargs); } @@ -665,7 +671,7 @@ int main(int argc, char *argv[]) image.div = beam->divergence; image.bw = beam->bandwidth; image.beam = beam; - image.filename = malloc(256); + image.filename = "dummy.h5"; image.copyme = NULL; image.crystals = NULL; image.n_crystals = 0; @@ -804,7 +810,6 @@ int main(int argc, char *argv[]) free(beam); free_symoplist(sym); reflist_free(full); - free(image.filename); return 0; } -- cgit v1.2.3