aboutsummaryrefslogtreecommitdiff
path: root/src/hdf5-file.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-01-18 18:02:21 +0100
committerThomas White <taw@physics.org>2010-01-18 18:02:21 +0100
commit825114565b26383f5de4d3e6aa384fd5192a8bf0 (patch)
treee3d7ca5c6334bb55d2fdc70ba38d897dd9a09445 /src/hdf5-file.c
parent132855ee98add703d220df30333b690809bf2b94 (diff)
Fix lots of memory leaks
Diffstat (limited to 'src/hdf5-file.c')
-rw-r--r--src/hdf5-file.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index 938422a7..32215c99 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -47,6 +47,7 @@ struct hdfile *hdfile_open(const char *filename)
f = malloc(sizeof(struct hdfile));
if ( f == NULL ) return NULL;
f->image = NULL;
+ f->image_dirty = 1;
f->fh = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
if ( f->fh < 0 ) {
@@ -55,8 +56,6 @@ struct hdfile *hdfile_open(const char *filename)
return NULL;
}
- f->image_dirty = 1;
-
return f;
}
@@ -104,7 +103,13 @@ int hdfile_get_height(struct hdfile *f)
void hdfile_close(struct hdfile *f)
{
H5Fclose(f->fh);
- free(f->image);
+ if ( f->image != NULL ) {
+ if ( f->image->features != NULL ) {
+ image_feature_list_free(f->image->features);
+ }
+ free(f->image->data);
+ free(f->image);
+ }
free(f);
}
@@ -160,6 +165,7 @@ int16_t *hdfile_get_image_binned(struct hdfile *f, int binning, int16_t *max)
image = malloc(sizeof(struct image));
if ( image == NULL ) return NULL;
image->features = NULL;
+ image->data = NULL;
hdf5_read(f, image);
@@ -167,7 +173,7 @@ int16_t *hdfile_get_image_binned(struct hdfile *f, int binning, int16_t *max)
if ( f->image != NULL ) {
image->features = f->image->features;
if ( f->image->data != NULL ) free(f->image->data);
- free(f->image);
+ free(f->image->data);
}
f->image = image;
@@ -490,7 +496,7 @@ int hdfile_set_first_image(struct hdfile *f, const char *group)
char **names;
int *is_group;
int *is_image;
- int n, i;
+ int n, i, j;
names = hdfile_read_group(f, &n, group, &is_group, &is_image);
if ( n == 0 ) return 1;
@@ -498,15 +504,30 @@ int hdfile_set_first_image(struct hdfile *f, const char *group)
for ( i=0; i<n; i++ ) {
if ( is_image[i] ) {
+ int j;
hdfile_set_image(f, names[i]);
+ for ( j=0; j<n; j++ ) free(names[j]);
+ free(is_image);
+ free(is_group);
+ free(names);
return 0;
} else if ( is_group[i] ) {
if ( !hdfile_set_first_image(f, names[i]) ) {
+ int j;
+ for ( j=0; j<n; j++ ) free(names[j]);
+ free(is_image);
+ free(is_group);
+ free(names);
return 0;
}
}
}
+ for ( j=0; j<n; j++ ) free(names[j]);
+ free(is_image);
+ free(is_group);
+ free(names);
+
return 1;
}