aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2023-07-27 13:35:47 +0200
committerThomas White <taw@physics.org>2023-07-27 13:43:15 +0200
commitbd215c1b3ee2a509c37c5fb2b81191c02c45b4b0 (patch)
tree1b3c9105833b922d5c794d728589e2d944449252
parente1001a658eb3b4328ddf086ef1d4f68b562ceb85 (diff)
Fix some more memory leaks
-rw-r--r--libcrystfel/src/datatemplate.c11
-rw-r--r--libcrystfel/src/image-hdf5.c17
-rw-r--r--src/im-sandbox.c2
3 files changed, 27 insertions, 3 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 4ec96cfd..e97ae3df 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -2003,9 +2003,14 @@ struct detgeom *create_detgeom(struct image *image,
detgeom->n_panels = dtempl->n_panels;
if ( two_d_only ) {
- if ( !detector_flat(dtempl) ) return NULL;
- if ( dtempl->shift_x_from != NULL ) return NULL;
- if ( dtempl->shift_y_from != NULL ) return NULL;
+ if ( !detector_flat(dtempl)
+ || (dtempl->shift_x_from != NULL)
+ || (dtempl->shift_y_from != NULL) )
+ {
+ free(detgeom->panels);
+ free(detgeom);
+ return NULL;
+ }
}
for ( i=0; i<dtempl->n_panels; i++ ) {
diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c
index c34dfc7b..66b93d90 100644
--- a/libcrystfel/src/image-hdf5.c
+++ b/libcrystfel/src/image-hdf5.c
@@ -954,6 +954,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name)
dim_vals[dim_val_pos], size[i]);
close_hdf5(fh);
free(subst_name);
+ free(dim_vals);
return 1;
}
@@ -969,6 +970,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name)
}
}
+ free(dim_vals);
check = H5Sselect_hyperslab(sh, H5S_SELECT_SET,
f_offset, NULL, f_count, NULL);
@@ -1334,12 +1336,14 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl,
dim_vals = read_dim_parts(event, &n_dim_vals);
if ( dim_vals == NULL ) {
ERROR("Couldn't parse event '%s'\n");
+ free(subst_name);
return NULL;
}
if ( n_dim_vals < 1 ) {
ERROR("Not enough dimensions in event ID to use CXI "
"peak lists (%i)\n", n_dim_vals);
+ free(subst_name);
return NULL;
}
@@ -1354,29 +1358,37 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl,
fh = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
if ( fh < 0 ) {
ERROR("Couldn't open file (peaks/cxi): %s\n", filename);
+ free(subst_name);
return NULL;
}
r = read_peak_count(fh, path_n, line, &num_peaks);
if ( r != 0 ) {
close_hdf5(fh);
+ free(subst_name);
return NULL;
}
buf_x = read_peak_line(fh, path_x, line, num_peaks);
if ( buf_x == NULL ) {
close_hdf5(fh);
+ free(subst_name);
return NULL;
}
buf_y = read_peak_line(fh, path_y, line, num_peaks);
if ( buf_y == NULL ) {
+ free(buf_x);
+ free(subst_name);
close_hdf5(fh);
return NULL;
}
buf_i = read_peak_line(fh, path_i, line, num_peaks);
if ( buf_i == NULL ) {
+ free(buf_x);
+ free(buf_y);
+ free(subst_name);
close_hdf5(fh);
return NULL;
}
@@ -1404,6 +1416,11 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl,
}
+ free(buf_x);
+ free(buf_y);
+ free(buf_i);
+ free(subst_name);
+
close_hdf5(fh);
return features;
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index c642988f..a91c6a87 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -286,6 +286,8 @@ static int get_pattern(struct get_pattern_ctx *gpctx,
if ( evstr != NULL ) {
*pfilename = filename;
*pevent = evstr;
+ free(gpctx->filename);
+ gpctx->filename = filename;
return 1;
}