From 6d94d4115c254d344bbb927596a7141ef39fd298 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 21 Jul 2021 11:51:56 +0200 Subject: Add missing cleanup on error paths --- libcrystfel/src/integration.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'libcrystfel/src/integration.c') 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; in_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; } -- cgit v1.2.3