From f5f19825380b91edf017af4f7353faf95f97508b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 4 Mar 2013 10:11:59 +0100 Subject: partialator: Fix various memory bugs --- src/partialator.c | 38 +++++++++++++++++++++++++++++--------- src/scaling-report.c | 7 +++++++ 2 files changed, 36 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/partialator.c b/src/partialator.c index 8b51f826..5613c14b 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -410,7 +410,7 @@ int main(int argc, char *argv[]) ERROR("Failed to open input stream '%s'\n", infile); return 1; } - free(infile); + /* Don't free "infile", because it's needed for the scaling report */ /* Sanitise output filename */ if ( outfile == NULL ) { @@ -453,7 +453,6 @@ int main(int argc, char *argv[]) gsl_set_error_handler_off(); /* Fill in what we know about the images so far */ - nobs = 0; n_images = 0; n_crystals = 0; images = NULL; @@ -495,6 +494,7 @@ int main(int argc, char *argv[]) Crystal *cr; Crystal **crystals_new; + RefList *cr_refl; crystals_new = realloc(crystals, (n_crystals+1)*sizeof(Crystal *)); @@ -506,20 +506,20 @@ int main(int argc, char *argv[]) crystals = crystals_new; crystals[n_crystals] = cur->crystals[i]; cr = crystals[n_crystals]; - crystal_set_image(cr, cur); + + /* Image pointer will change due to later reallocs */ + crystal_set_image(cr, NULL); /* Fill in initial estimates of stuff */ crystal_set_osf(cr, 1.0); crystal_set_profile_radius(cr, beam->profile_radius); - crystal_set_user_flag(cr, 0); + crystal_set_user_flag(cr, n_images); /* This is the raw list of reflections */ - as = asymmetric_indices(crystal_get_reflections(cr), - sym); + cr_refl = crystal_get_reflections(cr); + as = asymmetric_indices(cr_refl, sym); crystal_set_reflections(cr, as); - update_partialities(cr); - - nobs += select_scalable_reflections(as, reference); + reflist_free(cr_refl); n_crystals++; @@ -531,6 +531,26 @@ int main(int argc, char *argv[]) close_stream(st); + /* Fill in image pointers */ + nobs = 0; + for ( i=0; i