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 --- src/ambigator.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/ambigator.c') diff --git a/src/ambigator.c b/src/ambigator.c index 298002a7..1657bfb6 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -196,7 +196,7 @@ static struct flist *asymm_and_merge(RefList *in, const SymOpList *sym, || (f->s_reidx == NULL) || (f->i_reidx == NULL) || (f->group_reidx == NULL) || (f->group == NULL) ) { ERROR("Failed to allocate flist\n"); - return NULL; + goto out; } f->n = 0; @@ -218,7 +218,7 @@ static struct flist *asymm_and_merge(RefList *in, const SymOpList *sym, if ( amb != NULL ) { RefList *reidx = reflist_new(); - if ( reidx == NULL ) return NULL; + if ( reidx == NULL ) goto out; for ( refl = first_refl(asym, &iter); refl != NULL; @@ -236,7 +236,8 @@ static struct flist *asymm_and_merge(RefList *in, const SymOpList *sym, cr = add_refl(reidx, hra, kra, lra); if ( cr == NULL ) { ERROR("Failed to add reflection\n"); - return NULL; + reflist_free(reidx); + goto out; } copy_data(cr, refl); } @@ -260,6 +261,16 @@ static struct flist *asymm_and_merge(RefList *in, const SymOpList *sym, reflist_free(asym); return f; + +out: + free(f->s); + free(f->s_reidx); + free(f->i); + free(f->i_reidx); + free(f->group); + free(f->group_reidx); + free(f); + return NULL; } @@ -747,6 +758,7 @@ static void write_reindexed_stream(const char *infile, const char *outfile, ofh = fopen(outfile, "w"); if ( ofh == NULL ) { ERROR("Failed to open '%s'\n", outfile); + fclose(fh); return; } -- cgit v1.2.3