From 760f17f56b7f79f67a9029cbe7cc55a0acccd3b9 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 21 Jul 2021 12:11:42 +0200 Subject: Make sure that memory gets freed on realloc failure --- src/scaling.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/scaling.c b/src/scaling.c index cd4c5d92..6fab1626 100644 --- a/src/scaling.c +++ b/src/scaling.c @@ -259,13 +259,17 @@ int scale_one_crystal(Crystal *cr, const RefList *listR, int flags) if ( n == max_n ) { max_n *= 2; - x = realloc(x, max_n*sizeof(double)); - y = realloc(y, max_n*sizeof(double)); - w = realloc(w, max_n*sizeof(double)); + x = srealloc(x, max_n*sizeof(double)); + y = srealloc(y, max_n*sizeof(double)); + w = srealloc(w, max_n*sizeof(double)); if ( (x==NULL) || (y==NULL) || (w==NULL) ) { + free(x); + free(y); + free(w); ERROR("Failed to allocate memory for scaling.\n"); return 1; } + } x[n] = s*s; -- cgit v1.2.3