aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-01-25 09:31:34 +0100
committerThomas White <taw@physics.org>2019-01-28 14:55:31 +0100
commit9b1d07ba6ed79d2b32b1e8fa92bd93628f66b1c0 (patch)
tree12f43425f32555c4c0145b5fba1465302d2398d3 /src
parent9d7a9223c780ff9ce75fa4ccac2321a011ae640b (diff)
partialator: Fix multiple memory leaks
Diffstat (limited to 'src')
-rw-r--r--src/partialator.c8
-rw-r--r--src/post-refinement.c27
2 files changed, 19 insertions, 16 deletions
diff --git a/src/partialator.c b/src/partialator.c
index aacf241f..8b4893a5 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -1237,6 +1237,7 @@ int main(int argc, char *argv[])
ERROR("Unknown partiality model '%s'.\n", pmodel_str);
return 1;
}
+ free(pmodel_str);
}
if ( (pmodel == PMODEL_UNITY) && !no_pr ) {
@@ -1377,6 +1378,7 @@ int main(int argc, char *argv[])
*image = cur;
image->n_crystals = 1;
image->crystals = &crystals[n_crystals];
+ free(cur.crystals);
/* This is the raw list of reflections */
cr_refl = crystal_get_reflections(cr);
@@ -1420,6 +1422,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "\n");
if ( sparams_fh != NULL ) fclose(sparams_fh);
audit_info = stream_audit_info(st);
+ free(audit_info);
close_stream(st);
STATUS("Initial partiality calculation...\n");
@@ -1568,7 +1571,12 @@ int main(int argc, char *argv[])
/* Clean up */
gsl_rng_free(rng);
for ( i=0; i<n_crystals; i++ ) {
+ struct image *image = crystal_get_image(crystals[i]);
reflist_free(crystal_get_reflections(crystals[i]));
+ free_stuff_from_stream(image->stuff_from_stream);
+ free(image->filename);
+ free(image);
+ cell_free(crystal_get_cell(crystals[i]));
crystal_free(crystals[i]);
}
free_contribs(full);
diff --git a/src/post-refinement.c b/src/post-refinement.c
index 4ae72685..fd0d5c4e 100644
--- a/src/post-refinement.c
+++ b/src/post-refinement.c
@@ -84,17 +84,14 @@ const char *str_prflag(enum prflag flag)
}
-static UnitCell *rotate_cell_xy(const UnitCell *cell, double ang1, double ang2)
+static void rotate_cell_xy(UnitCell *cell, double ang1, double ang2)
{
- UnitCell *o;
double asx, asy, asz;
double bsx, bsy, bsz;
double csx, csy, csz;
double xnew, ynew, znew;
- o = cell_new_from_cell(cell);
-
- cell_get_reciprocal(o, &asx, &asy, &asz,
+ cell_get_reciprocal(cell, &asx, &asy, &asz,
&bsx, &bsy, &bsz,
&csx, &csy, &csz);
@@ -134,9 +131,7 @@ static UnitCell *rotate_cell_xy(const UnitCell *cell, double ang1, double ang2)
znew = -csx*sin(ang2) + csz*cos(ang2);
csx = xnew; csy = ynew; csz = znew;
- cell_set_reciprocal(o, asx, asy, asz, bsx, bsy, bsz, csx, csy, csz);
-
- return o;
+ cell_set_reciprocal(cell, asx, asy, asz, bsx, bsy, bsz, csx, csy, csz);
}
@@ -201,7 +196,6 @@ static void apply_parameters(const gsl_vector *v, const gsl_vector *initial,
{
int i;
double ang1, ang2, R, lambda;
- UnitCell *cell;
/* Default parameters if not used in refinement */
ang1 = 0.0;
@@ -240,9 +234,7 @@ static void apply_parameters(const gsl_vector *v, const gsl_vector *initial,
}
}
- cell = rotate_cell_xy(crystal_get_cell_const(cr), ang1, ang2);
- crystal_set_cell(cr, cell);
-
+ rotate_cell_xy(crystal_get_cell(cr), ang1, ang2);
crystal_set_profile_radius(cr, R);
crystal_get_image(cr)->lambda = lambda;
}
@@ -254,7 +246,6 @@ static double residual_f(const gsl_vector *v, void *pp)
RefList *list;
struct image im;
Crystal *cr;
- UnitCell *cell;
double res;
int i;
@@ -263,14 +254,14 @@ static double residual_f(const gsl_vector *v, void *pp)
}
cr = crystal_copy(pv->cr);
- cell = cell_new_from_cell(crystal_get_cell(cr));
- if ( cell == NULL ) return GSL_NAN;
- crystal_set_cell(cr, cell);
im = *crystal_get_image(cr);
crystal_set_image(cr, &im);
+ crystal_set_cell(cr, cell_new_from_cell(crystal_get_cell(cr)));
+
apply_parameters(v, pv->initial, pv->rv, cr);
if ( fabs(crystal_get_profile_radius(cr)) > 5e9 ) {
+ cell_free(crystal_get_cell(cr));
crystal_free(cr);
if ( pv->verbose ) STATUS("radius > 5e9\n");
return GSL_NAN;
@@ -278,12 +269,14 @@ static double residual_f(const gsl_vector *v, void *pp)
/* Can happen with grid scans and certain --force-radius values */
if ( fabs(crystal_get_profile_radius(cr)) < 0.0000001e9 ) {
+ cell_free(crystal_get_cell(cr));
crystal_free(cr);
if ( pv->verbose ) STATUS("radius very small\n");
return GSL_NAN;
}
if ( im.lambda <= 0.0 ) {
+ cell_free(crystal_get_cell(cr));
crystal_free(cr);
if ( pv->verbose ) STATUS("lambda < 0\n");
return GSL_NAN;
@@ -296,6 +289,8 @@ static double residual_f(const gsl_vector *v, void *pp)
calculate_partialities(cr, PMODEL_XSPHERE);
if ( scale_one_crystal(cr, pv->full, pv->scaleflags) ) {
+ cell_free(crystal_get_cell(cr));
+ reflist_free(crystal_get_reflections(cr));
crystal_free(cr);
if ( pv->verbose ) STATUS("Bad scaling\n");
return GSL_NAN;