aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/indexers
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-07-21 11:51:56 +0200
committerThomas White <taw@physics.org>2021-07-21 15:34:31 +0200
commit6d94d4115c254d344bbb927596a7141ef39fd298 (patch)
tree652d07c4d6a9521c9359aa13bbda27309f53e6f8 /libcrystfel/src/indexers
parent50cf52b0bc0baa683b9508568131a3f6281bf4ff (diff)
Add missing cleanup on error paths
Diffstat (limited to 'libcrystfel/src/indexers')
-rw-r--r--libcrystfel/src/indexers/asdf.c12
-rw-r--r--libcrystfel/src/indexers/felix.c2
-rw-r--r--libcrystfel/src/indexers/fromfile.c5
-rw-r--r--libcrystfel/src/indexers/mosflm.c2
-rw-r--r--libcrystfel/src/indexers/taketwo.c5
5 files changed, 23 insertions, 3 deletions
diff --git a/libcrystfel/src/indexers/asdf.c b/libcrystfel/src/indexers/asdf.c
index a8943688..7030a3e7 100644
--- a/libcrystfel/src/indexers/asdf.c
+++ b/libcrystfel/src/indexers/asdf.c
@@ -180,11 +180,18 @@ static struct asdf_cell *asdf_cell_new(int n)
if (c->reflections == NULL) return NULL;
c->indices = malloc(sizeof(double *) * n);
- if (c->indices == NULL) return NULL;
+ if (c->indices == NULL) {
+ free(c->reflections);
+ return NULL;
+ }
for ( i = 0; i < n; i++ ) {
c->indices[i] = malloc(sizeof(double) * 3);
- if (c->indices[i] == NULL) return NULL;
+ if (c->indices[i] == NULL) {
+ free(c->reflections);
+ free(c->indices);
+ return NULL;
+ }
}
c->n = 0;
@@ -973,6 +980,7 @@ static int index_refls(gsl_vector **reflections, int N_reflections,
struct tvector *tvectors = malloc(N_triplets * sizeof(struct tvector));
if (tvectors == NULL) {
ERROR("Failed to allocate tvectors in index_refls!\n");
+ free(fits);
return 0;
}
diff --git a/libcrystfel/src/indexers/felix.c b/libcrystfel/src/indexers/felix.c
index db9cccf8..b7d2a8a3 100644
--- a/libcrystfel/src/indexers/felix.c
+++ b/libcrystfel/src/indexers/felix.c
@@ -143,6 +143,7 @@ static int read_felix(struct felix_private *gp, struct image *image,
/* Read and discard first line */
if ( fgets( line, 1024, fh ) == NULL ) {
ERROR("Failed to read *.felix file.\n");
+ fclose(fh);
return 0;
}
@@ -639,6 +640,7 @@ void *felix_prepare(IndexingMethod *indm, UnitCell *cell,
if ( gp->spacegroup == 0 ) {
ERROR("Couldn't determine representative space group for your cell.\n");
ERROR("Try again with a more conventional cell.\n");
+ free(gp);
return NULL;
}
diff --git a/libcrystfel/src/indexers/fromfile.c b/libcrystfel/src/indexers/fromfile.c
index f0372489..d7dfbd09 100644
--- a/libcrystfel/src/indexers/fromfile.c
+++ b/libcrystfel/src/indexers/fromfile.c
@@ -211,7 +211,10 @@ void *fromfile_prepare(IndexingMethod *indm, struct fromfile_options *opts)
}
dp = malloc(sizeof(struct fromfile_private));
- if ( dp == NULL ) return NULL;
+ if ( dp == NULL ) {
+ fclose(fh);
+ return NULL;
+ }
dp->sol_hash = NULL;
diff --git a/libcrystfel/src/indexers/mosflm.c b/libcrystfel/src/indexers/mosflm.c
index c56f3ae6..129e6859 100644
--- a/libcrystfel/src/indexers/mosflm.c
+++ b/libcrystfel/src/indexers/mosflm.c
@@ -244,6 +244,7 @@ static int read_newmat(struct mosflm_data *mosflm, const char *filename,
n += fscanf(fh, "%f %f %f\n", &asz, &bsz, &csz);
if ( n != 9 ) {
STATUS("Fewer than 9 parameters found in NEWMAT file.\n");
+ fclose(fh);
return 1;
}
@@ -371,6 +372,7 @@ static void write_img(struct image *image, const char *filename)
fh = fopen(filename, "w");
if ( !fh ) {
ERROR("Couldn't open temporary file '%s'\n", filename);
+ free(intimage);
return;
}
diff --git a/libcrystfel/src/indexers/taketwo.c b/libcrystfel/src/indexers/taketwo.c
index 60bb6fed..cd4d87a6 100644
--- a/libcrystfel/src/indexers/taketwo.c
+++ b/libcrystfel/src/indexers/taketwo.c
@@ -1769,6 +1769,10 @@ static int match_obs_to_cell_vecs(struct TheoryVec *cell_vecs, int cell_vec_coun
match_array = &(obs_vecs[i].matches);
match_count = &(obs_vecs[i].match_num);
+ if ( for_sort == NULL ) {
+ return 0;
+ }
+
/* Sort in order to get most agreeable matches first */
qsort(for_sort, count, sizeof(struct sortme), sort_theory_distances);
*match_array = malloc(count*sizeof(struct TheoryVec));
@@ -1831,6 +1835,7 @@ static int gen_observed_vecs(struct rvec *rlps, int rlp_count,
spot_vec.match_num = 0;
spot_vec.her_rlp = &rlps[i];
spot_vec.his_rlp = &rlps[j];
+ spot_vec.in_network = 0;
cell->obs_vecs[count - 1] = spot_vec;
}