From 825114565b26383f5de4d3e6aa384fd5192a8bf0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 18 Jan 2010 18:02:21 +0100 Subject: Fix lots of memory leaks --- src/hdf5-file.c | 31 ++++++++++++++++++++++++++----- src/indexamajig.c | 5 +++++ 2 files changed, 31 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 #include #include +#include #include "utils.h" #include "hdf5-file.h" @@ -124,6 +125,7 @@ int main(int argc, char *argv[]) image.features = NULL; image.molecule = NULL; + image.data = NULL; STATUS("Processing '%s'\n", line); @@ -162,6 +164,9 @@ int main(int argc, char *argv[]) } + free(image.data); + hdfile_close(hdfile); + } while ( rval != NULL ); fclose(fh); -- cgit v1.2.3