aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-07-21 12:11:42 +0200
committerThomas White <taw@physics.org>2021-07-21 15:34:33 +0200
commit760f17f56b7f79f67a9029cbe7cc55a0acccd3b9 (patch)
tree608a86b923abe5564c7d1624f54fdf9b90b9a6ee /src
parent6d94d4115c254d344bbb927596a7141ef39fd298 (diff)
Make sure that memory gets freed on realloc failure
Diffstat (limited to 'src')
-rw-r--r--src/scaling.c10
1 files changed, 7 insertions, 3 deletions
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;