diff options
author | Thomas White <taw@bitwiz.org.uk> | 2014-03-18 15:51:10 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2014-03-18 15:51:10 +0100 |
commit | caf1fdaafe4f4e2c64caacb86960e4fc831aded3 (patch) | |
tree | ec81c705a0d54b6c2f719f22be21faa0f79e8e5a /src | |
parent | f3b3b56971cb3027539531d84277482cbdc66591 (diff) |
partial_sim: Fix filename memory corruption when using -j
Diffstat (limited to 'src')
-rw-r--r-- | src/partial_sim.c | 9 |
1 files changed, 7 insertions, 2 deletions
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; } |