aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/integration.c
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/integration.c
parent50cf52b0bc0baa683b9508568131a3f6281bf4ff (diff)
Add missing cleanup on error paths
Diffstat (limited to 'libcrystfel/src/integration.c')
-rw-r--r--libcrystfel/src/integration.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c
index b2b6ccfa..326e3183 100644
--- a/libcrystfel/src/integration.c
+++ b/libcrystfel/src/integration.c
@@ -509,6 +509,7 @@ struct intcontext *intcontext_new(struct image *image,
ic->bm = malloc(ic->w * ic->w * sizeof(enum boxmask_val));
if ( ic->bm == NULL ) {
ERROR("Failed to allocate box mask.\n");
+ free(ic);
return NULL;
}
@@ -516,12 +517,21 @@ struct intcontext *intcontext_new(struct image *image,
ic->n_reference_profiles = 1;
ic->reference_profiles = calloc(ic->n_reference_profiles,
sizeof(double *));
- if ( ic->reference_profiles == NULL ) return NULL;
+ if ( ic->reference_profiles == NULL ) {
+ free(ic);
+ return NULL;
+ }
ic->reference_den = calloc(ic->n_reference_profiles, sizeof(double *));
- if ( ic->reference_den == NULL ) return NULL;
+ if ( ic->reference_den == NULL ) {
+ free(ic);
+ return NULL;
+ }
ic->n_profiles_in_reference = calloc(ic->n_reference_profiles,
sizeof(int));
- if ( ic->n_profiles_in_reference == NULL ) return NULL;
+ if ( ic->n_profiles_in_reference == NULL ) {
+ free(ic);
+ return NULL;
+ }
for ( i=0; i<ic->n_reference_profiles; i++ ) {
ic->reference_profiles[i] = malloc(ic->w*ic->w*sizeof(double));
if ( ic->reference_profiles[i] == NULL ) return NULL;
@@ -534,6 +544,7 @@ struct intcontext *intcontext_new(struct image *image,
ic->n_boxes = 0;
ic->max_boxes = 0;
if ( alloc_boxes(ic, 32) ) {
+ free(ic);
return NULL;
}