From e91c5069976910212badaa955b24cf6ba83a47a0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 6 Oct 2015 17:25:10 +0200 Subject: Fussiness --- libcrystfel/src/hdf5-file.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c index bd0124fd..720f6e0f 100644 --- a/libcrystfel/src/hdf5-file.c +++ b/libcrystfel/src/hdf5-file.c @@ -3,11 +3,11 @@ * * Read/write HDF5 data files * - * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * * Authors: - * 2009-2012 Thomas White + * 2009-2015 Thomas White * 2014 Valerio Mariani * * This file is part of CrystFEL. @@ -727,18 +727,18 @@ static struct hdf5_write_location *make_location_list(struct detector *det, for ( pi=0; pin_panels; pi++ ) { - struct panel p; + struct panel *p; const char *p_location; - p = det->panels[pi]; + p = &det->panels[pi]; - if ( p.data == NULL ) { + if ( p->data == NULL ) { p_location = def_location; } else { - p_location = p.data; + p_location = p->data; } - add_panel_location(&p, p_location, pi, + add_panel_location(p, p_location, pi, &locations, &num_locations); } -- cgit v1.2.3 From 926f8c5df4c48cab75c98fa670bb84c9f917368e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 7 Oct 2015 10:56:32 +0200 Subject: Fix a small memory leak --- src/dw-hdfsee.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index 5362bca7..e0c702a9 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -2407,6 +2407,7 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile, free(is_group); free(is_image); + free(names); return ms; } -- cgit v1.2.3 From deac92ded829656583760b80308f00d1ee8bfa53 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 7 Oct 2015 10:58:17 +0200 Subject: Formatting --- src/dw-hdfsee.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c index e0c702a9..f66f37b5 100644 --- a/src/dw-hdfsee.c +++ b/src/dw-hdfsee.c @@ -2380,7 +2380,7 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile, if ( hdfile_is_scalar(hdfile, names[i], 0) ) { tmp = hdfile_get_string_value(hdfile, names[i], - NULL); + NULL); } else { tmp = NULL; } -- cgit v1.2.3 From faef0b78ac34d0ea2cdc98f7137b504aac94e9d5 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 7 Oct 2015 12:03:51 +0200 Subject: hdfile_get_string_value(): Rearrange control flow This is not a nice function, and seemed to contain a weird stack corruption somewhere. It is still not a nice function, but at least no longer seems to contain a weird stack corruption. --- libcrystfel/src/hdf5-file.c | 52 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c index 720f6e0f..e7b6eed4 100644 --- a/libcrystfel/src/hdf5-file.c +++ b/libcrystfel/src/hdf5-file.c @@ -1926,7 +1926,10 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, } dh = H5Dopen2(f->fh, subst_name, H5P_DEFAULT); - if ( dh < 0 ) return NULL; + if ( dh < 0 ) { + free(subst_name); + return NULL; + } type = H5Dget_type(dh); class = H5Tget_class(type); @@ -1938,6 +1941,8 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, v = H5Tis_variable_str(type); if ( v < 0 ) { + H5Tclose(type); + free(subst_name); return "WTF?"; } @@ -1946,9 +1951,13 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, r = H5Dread(dh, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, &tmp); if ( r < 0 ) { - tmp = NULL; + H5Tclose(type); + free(subst_name); + return NULL; } + return tmp; + } else { size = H5Tget_size(type); @@ -1957,9 +1966,11 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, sh = H5Screate(H5S_SCALAR); r = H5Dread(dh, type, sh, sh, H5P_DEFAULT, tmp); + H5Sclose(sh); if ( r < 0 ) { free(tmp); - tmp = NULL; + free(subst_name); + return NULL; } else { /* Two possibilities: @@ -1968,17 +1979,20 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, * Make sure things are done properly... */ tmp[size] = '\0'; chomp(tmp); + H5Dclose(dh); + free(subst_name); + return tmp; } - H5Sclose(sh); - } - } else { int r; + H5Dclose(dh); + H5Tclose(type); + switch ( class ) { case H5T_FLOAT : @@ -1986,7 +2000,15 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, H5T_NATIVE_DOUBLE); if ( r == 0 ) { tmp = malloc(256); + if ( tmp == NULL ) { + ERROR("Failed to allocate float\n"); + return NULL; + } snprintf(tmp, 255, "%f", buf_f); + return tmp; + } else { + ERROR("Failed to read value\n"); + return NULL; } break; @@ -1995,17 +2017,25 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, H5T_NATIVE_INT); if ( r == 0 ) { tmp = malloc(256); + if ( tmp == NULL ) { + ERROR("Failed to allocate int buf!\n"); + return NULL; + } snprintf(tmp, 255, "%d", buf_i); + return tmp; + + } else { + ERROR("Failed to read value\n"); + return NULL; } break; + + default : + ERROR("Don't know what to do!\n"); + return NULL; } } - - H5Tclose(type); - H5Dclose(dh); - free(subst_name); - return tmp; } -- cgit v1.2.3