summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-10 17:43:14 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-10 17:43:14 (GMT)
commit9d06256018fbebbefa08879ae9f16696a5bbef19 (patch)
treedb84f4d812d122c8c9fafbcc4b828fc12cbf6a8e /tools
parenta4750dfae7e187f95c4515939968e6fce880efed (diff)
downloadhdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.zip
hdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.tar.gz
hdf5-9d06256018fbebbefa08879ae9f16696a5bbef19.tar.bz2
[svn-r17987] Description:
Bring r17945:17986 from trunk to revise_chunks branch (needs to have autotools files regenerated before testing, those will be checked in in a few minutes)
Diffstat (limited to 'tools')
-rw-r--r--tools/h5dump/h5dump.c6
-rw-r--r--tools/h5dump/h5dumpgentest.c93
-rwxr-xr-xtools/h5import/h5import.c25
-rwxr-xr-xtools/h5import/h5import.h3
-rw-r--r--tools/h5jam/h5jamgentest.c2
-rw-r--r--tools/h5repack/h5repack.c22
-rw-r--r--tools/h5repack/h5repack_opttable.c18
-rw-r--r--tools/h5repack/h5repacktst.c49
-rw-r--r--tools/lib/h5diff_array.c97
-rw-r--r--tools/lib/h5diff_dset.c26
-rw-r--r--tools/lib/h5tools.c55
11 files changed, 240 insertions, 156 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index a437619..abe97ea 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -5749,7 +5749,6 @@ xml_dump_group(hid_t gid, const char *name)
char type_name[1024], *tmp = NULL;
char *par = NULL;
int isRoot = 0;
- char *ptrstr;
char *t_objname;
char *par_name;
unsigned crt_order_flags;
@@ -5802,6 +5801,7 @@ xml_dump_group(hid_t gid, const char *name)
indent += COL;
H5Oget_info(gid, &oinfo);
+
if(oinfo.rc > 1) {
obj_t *found_obj; /* Found object */
@@ -5819,6 +5819,8 @@ xml_dump_group(hid_t gid, const char *name)
char *parentxid = malloc(100);
if(found_obj->displayed) {
+ char *ptrstr = malloc(100);
+
/* already seen: enter a groupptr */
if(isRoot) {
/* probably can't happen! */
@@ -5839,7 +5841,6 @@ xml_dump_group(hid_t gid, const char *name)
}
indentation(indent + COL);
- ptrstr = malloc(100);
t_objname = xml_escape_the_name(found_obj->objname);/* point to the NDT by name */
par_name = xml_escape_the_name(par);
xml_name_to_XID(found_obj->objname, ptrstr, 100, 1);
@@ -5850,6 +5851,7 @@ xml_dump_group(hid_t gid, const char *name)
ptrstr, t_objname, parentxid, par_name);
free(t_objname);
free(par_name);
+ free(ptrstr);
} else {
/* first time this group has been seen -- describe it */
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c
index b42b675..ab60807 100644
--- a/tools/h5dump/h5dumpgentest.c
+++ b/tools/h5dump/h5dumpgentest.c
@@ -5813,12 +5813,12 @@ gent_binary(void)
static void
gent_bigdims(void)
{
- hid_t fid;
- hid_t did;
- hid_t f_sid;
- hid_t m_sid;
- hid_t tid;
- hid_t dcpl;
+ hid_t fid = -1;
+ hid_t did = -1;
+ hid_t f_sid = -1;
+ hid_t m_sid = -1;
+ hid_t tid = -1;
+ hid_t dcpl = -1;
hsize_t dims[1]={DIM_4GB}; /* dataset dimensions */
hsize_t chunk_dims[1]={1024}; /* chunk dimensions */
hsize_t hs_start[1];
@@ -5876,14 +5876,21 @@ gent_bigdims(void)
buf=NULL;
/* close */
+ if(H5Tclose(tid) < 0)
+ goto out;
+ tid = -1;
if(H5Sclose(f_sid) < 0)
goto out;
+ f_sid = -1;
if(H5Sclose(m_sid) < 0)
goto out;
+ m_sid = -1;
if(H5Pclose(dcpl) < 0)
goto out;
+ dcpl = -1;
if(H5Dclose(did) < 0)
goto out;
+ did = -1;
ret = H5Fclose(fid);
assert(ret >= 0);
@@ -5896,11 +5903,11 @@ out:
H5Pclose(dcpl);
H5Sclose(f_sid);
H5Sclose(m_sid);
+ H5Tclose(tid);
H5Dclose(did);
H5Fclose(fid);
} H5E_END_TRY;
return;
-
}
@@ -5947,10 +5954,10 @@ gent_hyperslab(void)
static void
gent_group_creation_order(void)
{
- hid_t fid; /* file ID */
- hid_t gid; /* group ID */
- hid_t gcpl_id; /* group creation property list ID */
- hid_t fcpl_id; /* file creation property list ID (to set root group order) */
+ hid_t fid = -1; /* file ID */
+ hid_t gid = -1; /* group ID */
+ hid_t gcpl_id = -1; /* group creation property list ID */
+ hid_t fcpl_id = -1; /* file creation property list ID (to set root group order) */
if((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0)
goto out;
@@ -5976,37 +5983,45 @@ gent_group_creation_order(void)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "2/c", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "2/b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "2/a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "2/a/a2", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "2/a/a1", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "2/a/a2/a22", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "2/a/a2/a21", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
/*-------------------------------------------------------------------------
@@ -6021,45 +6036,56 @@ gent_group_creation_order(void)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "1/c", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "1/b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "1/a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "1/a/a2", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "1/a/a1", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "1/a/a2/a22", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if((gid = H5Gcreate2(fid, "1/a/a2/a21", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
if(H5Pclose(gcpl_id) < 0)
goto out;
+ gcpl_id = -1;
if(H5Pclose(fcpl_id) < 0)
goto out;
+ fcpl_id = -1;
if(H5Fclose(fid) < 0)
goto out;
+ fid = -1;
return;
@@ -6087,15 +6113,15 @@ out:
static void
gent_attr_creation_order(void)
{
- hid_t fid; /* file id */
- hid_t gid; /* group id */
- hid_t did; /* dataset id */
- hid_t sid; /* space id */
- hid_t aid; /* attribute id */
- hid_t tid; /* datatype id */
- hid_t gcpl_id; /* group creation property list ID */
- hid_t dcpl_id; /* dataset creation property list ID */
- hid_t tcpl_id; /* datatype creation property list ID */
+ hid_t fid = -1; /* file id */
+ hid_t gid = -1; /* group id */
+ hid_t did = -1; /* dataset id */
+ hid_t sid = -1; /* space id */
+ hid_t aid = -1; /* attribute id */
+ hid_t tid = -1; /* datatype id */
+ hid_t gcpl_id = -1; /* group creation property list ID */
+ hid_t dcpl_id = -1; /* dataset creation property list ID */
+ hid_t tcpl_id = -1; /* datatype creation property list ID */
int i;
const char *attr_name[3] = {"c", "b", "a" };
@@ -6148,10 +6174,12 @@ gent_attr_creation_order(void)
/* close attribute */
if(H5Aclose(aid) < 0)
goto out;
+ aid = -1;
} /* end for */
if(H5Dclose(did) < 0)
goto out;
+ did = -1;
/*-------------------------------------------------------------------------
@@ -6172,10 +6200,12 @@ gent_attr_creation_order(void)
/* close attribute */
if(H5Aclose(aid) < 0)
goto out;
+ aid = -1;
} /* end for */
if(H5Dclose(did) < 0)
goto out;
+ did = -1;
@@ -6196,11 +6226,12 @@ gent_attr_creation_order(void)
/* close attribute */
if(H5Aclose(aid) < 0)
goto out;
-
+ aid = -1;
} /* end for */
if(H5Gclose(gid) < 0)
goto out;
+ gid = -1;
/*-------------------------------------------------------------------------
* create a group without creation order tracked for attributes and atributes in it
@@ -6219,12 +6250,12 @@ gent_attr_creation_order(void)
/* close attribute */
if(H5Aclose(aid) < 0)
goto out;
-
+ aid = -1;
} /* end for */
if(H5Gclose(gid) < 0)
goto out;
-
+ gid = -1;
/*-------------------------------------------------------------------------
* create a named datatype with creation order tracked for attributes and atributes in it
@@ -6246,11 +6277,12 @@ gent_attr_creation_order(void)
/* close attribute */
if(H5Aclose(aid) < 0)
goto out;
-
+ aid = -1;
} /* end for */
if(H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* create a named datatype without creation order tracked for attributes and atributes in it
@@ -6272,11 +6304,12 @@ gent_attr_creation_order(void)
/* close attribute */
if(H5Aclose(aid) < 0)
goto out;
-
+ aid = -1;
} /* end for */
if(H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* add some attributes to the root group
@@ -6294,12 +6327,12 @@ gent_attr_creation_order(void)
/* close attribute */
if(H5Aclose(aid) < 0)
goto out;
-
+ aid = -1;
} /* end for */
if(H5Gclose(gid) < 0)
goto out;
-
+ gid = -1;
/*-------------------------------------------------------------------------
* close
@@ -6307,15 +6340,19 @@ gent_attr_creation_order(void)
*/
if(H5Sclose(sid) < 0)
goto out;
-
+ sid = -1;
if(H5Pclose(dcpl_id) < 0)
goto out;
+ dcpl_id = -1;
if(H5Pclose(gcpl_id) < 0)
goto out;
+ gcpl_id = -1;
if(H5Pclose(tcpl_id) < 0)
goto out;
+ tcpl_id = -1;
if(H5Fclose(fid) < 0)
goto out;
+ fid = -1;
diff --git a/tools/h5import/h5import.c b/tools/h5import/h5import.c
index 3818829..60ef494 100755
--- a/tools/h5import/h5import.c
+++ b/tools/h5import/h5import.c
@@ -1587,16 +1587,29 @@ static int
parsePathInfo(struct path_info *path, char *temp)
{
const char delimiter[] = "/";
- char *token = (char*) malloc(255*sizeof(char));
+ char *token;
int i=0;
+ const char *err1 = "Path string larger than MAX_PATH_NAME_LENGTH.\n";
+
+ token = HDstrtok (temp, delimiter);
+ if (HDstrlen(token) >= MAX_PATH_NAME_LENGTH)
+ {
+ (void) fprintf(stderr, err1);
+ return (-1);
+ }
+ HDstrcpy(path->group[i++],token);
- HDstrcpy(path->group[i++],HDstrtok (temp, delimiter));
while (1)
{
token = HDstrtok (NULL, delimiter);
if (token == NULL)
break;
+ if (HDstrlen(token) >= MAX_PATH_NAME_LENGTH)
+ {
+ (void) fprintf(stderr, err1);
+ return (-1);
+ }
HDstrcpy(path->group[i++],token);
}
path->count = i;
@@ -1608,11 +1621,12 @@ parseDimensions(struct Input *in, char *strm)
{
const char delimiter[] = ",";
char temp[255];
- char *token = (char*) malloc(255*sizeof(char));
+ char *token;
int i=0;
const char *err1 = "Unable to allocate dynamic memory.\n";
- HDstrcpy(temp, strm);
+ HDstrncpy(temp, strm, sizeof(temp));
+ temp[sizeof(temp)-1] = '\0';
HDstrtok (temp, delimiter);
while (1)
@@ -1631,7 +1645,8 @@ parseDimensions(struct Input *in, char *strm)
}
i=0;
- HDstrcpy(temp, strm);
+ HDstrncpy(temp, strm, sizeof(temp));
+ temp[sizeof(temp)-1] = '\0';
in->sizeOfDimension[i++] = HDstrtol(HDstrtok (temp, delimiter), NULL, BASE_10);
while (1)
diff --git a/tools/h5import/h5import.h b/tools/h5import/h5import.h
index c43b0cf..cbc6bf2 100755
--- a/tools/h5import/h5import.h
+++ b/tools/h5import/h5import.h
@@ -38,6 +38,7 @@
#define ERR 20 /* invalid token */
#define MAX_GROUPS_IN_PATH 20
+#define MAX_PATH_NAME_LENGTH 255
#define NUM_KEYS 14
#define MIN_NUM_DIMENSION 1
#define MAX_NUM_DIMENSION 32
@@ -73,7 +74,7 @@
struct path_info
{
- char group[MAX_GROUPS_IN_PATH][255];
+ char group[MAX_GROUPS_IN_PATH][MAX_PATH_NAME_LENGTH];
int count;
};
diff --git a/tools/h5jam/h5jamgentest.c b/tools/h5jam/h5jamgentest.c
index 5a3d828..96d113e 100644
--- a/tools/h5jam/h5jamgentest.c
+++ b/tools/h5jam/h5jamgentest.c
@@ -345,6 +345,8 @@ create_textfile(const char *name, size_t size)
HDwrite(fd, buf, size);
+ free(buf);
+
HDclose(fd);
}
diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c
index c8a3abe..addcea3 100644
--- a/tools/h5repack/h5repack.c
+++ b/tools/h5repack/h5repack.c
@@ -114,6 +114,7 @@ h5repack_init(pack_opt_t *options, int verbose, int latest,
return (options_table_init(&(options->op_tbl)));
}
+
/*-------------------------------------------------------------------------
* Function: h5repack_end
*
@@ -127,6 +128,7 @@ int h5repack_end (pack_opt_t *options)
return options_table_free(options->op_tbl);
}
+
/*-------------------------------------------------------------------------
* Function: h5repack_addfilter
*
@@ -137,7 +139,6 @@ int h5repack_end (pack_opt_t *options)
*
*-------------------------------------------------------------------------
*/
-
int h5repack_addfilter(const char* str,
pack_opt_t *options)
{
@@ -149,38 +150,33 @@ int h5repack_addfilter(const char* str,
/* parse the -f option */
- obj_list=parse_filter(str,&n_objs,&filter,options,&is_glb);
- if (obj_list==NULL)
- {
+ if(NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb)))
return -1;
- }
/* if it applies to all objects */
- if (is_glb)
+ if(is_glb)
{
-
int n;
n = options->n_filter_g++; /* increase # of global filters */
- if (options->n_filter_g > H5_REPACK_MAX_NFILTERS)
+ if(options->n_filter_g > H5_REPACK_MAX_NFILTERS)
{
- error_msg(progname, "maximum number of filters exceeded for <%s>\n",str);
+ error_msg(progname, "maximum number of filters exceeded for <%s>\n", str);
+ free(obj_list);
return -1;
-
}
options->filter_g[n] = filter;
}
-
else
- options_add_filter(obj_list,n_objs,filter,options->op_tbl);
+ options_add_filter(obj_list, n_objs, filter, options->op_tbl);
free(obj_list);
return 0;
}
-
+
/*-------------------------------------------------------------------------
* Function: h5repack_addlayout
*
diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c
index 5b6d5d0..7c87359 100644
--- a/tools/h5repack/h5repack_opttable.c
+++ b/tools/h5repack/h5repack_opttable.c
@@ -136,6 +136,7 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs )
return 0;
}
+
/*-------------------------------------------------------------------------
* Function: options_table_init
*
@@ -145,33 +146,34 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs )
*
*-------------------------------------------------------------------------
*/
-
int options_table_init( pack_opttbl_t **tbl )
{
unsigned int i;
- pack_opttbl_t* table = (pack_opttbl_t*) malloc(sizeof(pack_opttbl_t));
- if (table==NULL) {
+ pack_opttbl_t *table;
+
+ if(NULL == (table = (pack_opttbl_t *)malloc(sizeof(pack_opttbl_t))))
+ {
error_msg(progname, "not enough memory for options table\n");
return -1;
}
table->size = 30;
table->nelems = 0;
- table->objs = (pack_info_t*) malloc(table->size * sizeof(pack_info_t));
- if (table->objs==NULL) {
+ if(NULL == (table->objs = (pack_info_t*)malloc(table->size * sizeof(pack_info_t))))
+ {
error_msg(progname, "not enough memory for options table\n");
+ free(table);
return -1;
}
- for ( i=0; i<table->size; i++)
- {
+ for(i = 0; i < table->size; i++)
init_packobject(&table->objs[i]);
- }
*tbl = table;
return 0;
}
+
/*-------------------------------------------------------------------------
* Function: options_table_free
*
diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c
index adaef43..aad3df4 100644
--- a/tools/h5repack/h5repacktst.c
+++ b/tools/h5repack/h5repacktst.c
@@ -4105,6 +4105,7 @@ int make_dset_reg_ref(hid_t loc_id)
hdset_reg_ref_t *wbuf=NULL; /* buffer to write to disk */
int *dwbuf=NULL; /* Buffer for writing numeric data to disk */
int i; /* counting variables */
+ int retval = -1; /* return value */
/* Allocate write & read buffers */
wbuf = (hdset_reg_ref_t *)calloc(sizeof(hdset_reg_ref_t), (size_t)SPACE1_DIM1);
@@ -4160,24 +4161,23 @@ int make_dset_reg_ref(hid_t loc_id)
if (H5Dclose(did2) < 0)
goto out;
- if (wbuf)
+ retval = 0;
+
+out:
+ if(wbuf)
free(wbuf);
- if (dwbuf)
+ if(dwbuf)
free(dwbuf);
- return 0;
-
-out:
H5E_BEGIN_TRY
{
-
H5Sclose(sid1);
H5Sclose(sid2);
H5Dclose(did1);
H5Dclose(did2);
-
} H5E_END_TRY;
- return -1;
+
+ return retval;
}
/*-------------------------------------------------------------------------
@@ -4211,9 +4211,9 @@ int write_attr_in(hid_t loc_id,
GREEN
} e_t;
- hid_t aid;
- hid_t sid;
- hid_t tid;
+ hid_t aid = -1;
+ hid_t sid = -1;
+ hid_t tid = -1;
int val, i, j, k, n;
float f;
@@ -4295,6 +4295,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_BITFIELD
@@ -4324,6 +4325,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_OPAQUE
@@ -4350,6 +4352,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_COMPOUND
@@ -4387,6 +4390,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_REFERENCE
@@ -4435,6 +4439,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_VLEN
@@ -4479,10 +4484,13 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Aclose(aid) < 0)
goto out;
+ aid = -1;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
if (H5Sclose(sid) < 0)
goto out;
+ sid = -1;
/*-------------------------------------------------------------------------
* H5T_ARRAY
@@ -4517,6 +4525,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_INTEGER and H5T_FLOAT
@@ -4594,6 +4603,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_BITFIELD
@@ -4626,6 +4636,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_OPAQUE
@@ -4653,6 +4664,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_COMPOUND
@@ -4688,6 +4700,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_REFERENCE
@@ -4742,6 +4755,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_VLEN
@@ -4791,10 +4805,13 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Aclose(aid) < 0)
goto out;
+ aid = -1;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
if (H5Sclose(sid) < 0)
goto out;
+ sid = -1;
/*-------------------------------------------------------------------------
* H5T_ARRAY
@@ -4837,6 +4854,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_INTEGER and H5T_FLOAT
@@ -4956,6 +4974,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_BITFIELD
@@ -5010,6 +5029,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_OPAQUE
@@ -5023,6 +5043,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_COMPOUND
@@ -5113,6 +5134,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_REFERENCE
@@ -5197,6 +5219,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_VLEN
@@ -5251,10 +5274,13 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Aclose(aid) < 0)
goto out;
+ aid = -1;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
if (H5Sclose(sid) < 0)
goto out;
+ sid = -1;
/*-------------------------------------------------------------------------
* H5T_ARRAY
@@ -5288,6 +5314,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_INTEGER and H5T_FLOAT
diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c
index 848ba90..91acb10 100644
--- a/tools/lib/h5diff_array.c
+++ b/tools/lib/h5diff_array.c
@@ -5810,6 +5810,51 @@ int print_data(diff_opt_t *options)
}
/*-------------------------------------------------------------------------
+ * Function: print_header
+ *
+ * Purpose: print header for difference
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static
+void print_header(int pp, /* print percentage */
+ int rank,
+ hsize_t *dims,
+ const char *obj1,
+ const char *obj2 )
+{
+ int i;
+
+ /* print header */
+ parallel_print("%-16s","size:");
+ print_dimensions (rank,dims);
+ parallel_print("%-11s","");
+ print_dimensions (rank,dims);
+ parallel_print("\n");
+
+ if (pp)
+ {
+ parallel_print("%-15s %-15s %-15s %-15s %-15s\n",
+ "position",
+ (obj1!=NULL) ? obj1 : " ",
+ (obj2!=NULL) ? obj2 : " ",
+ "difference",
+ "relative");
+ parallel_print("------------------------------------------------------------------------\n");
+ }
+ else
+ {
+ parallel_print("%-15s %-15s %-15s %-20s\n",
+ "position",
+ (obj1!=NULL) ? obj1 : " ",
+ (obj2!=NULL) ? obj2 : " ",
+ "difference");
+ parallel_print("------------------------------------------------------------\n");
+ }
+}
+
+/*-------------------------------------------------------------------------
* Function: print_pos
*
* Purpose: print in matrix notation, converting from an array index position
@@ -5835,31 +5880,7 @@ void print_pos( int *ph, /* print header */
{
*ph=0;
- parallel_print("%-16s","size:");
- print_dimensions (rank,dims);
- parallel_print("%-11s","");
- print_dimensions (rank,dims);
- parallel_print("\n");
-
- if (pp)
- {
- parallel_print("%-15s %-15s %-15s %-15s %-15s\n",
- "position",
- (obj1!=NULL) ? obj1 : " ",
- (obj2!=NULL) ? obj2 : " ",
- "difference",
- "relative");
- parallel_print("------------------------------------------------------------------------\n");
- }
- else
- {
- parallel_print("%-15s %-15s %-15s %-20s\n",
- "position",
- (obj1!=NULL) ? obj1 : " ",
- (obj2!=NULL) ? obj2 : " ",
- "difference");
- parallel_print("------------------------------------------------------------\n");
- }
+ print_header(pp, rank, dims, obj1, obj2);
} /* end print header */
for ( i = 0; i < rank; i++)
@@ -5912,31 +5933,7 @@ void print_char_pos( int *ph, /* print header */
{
*ph=0;
- parallel_print("%-16s","size:");
- print_dimensions (rank,dims);
- parallel_print("%-11s","");
- print_dimensions (rank,dims);
- parallel_print("\n");
-
- if (pp)
- {
- parallel_print("%-15s %-15s %-15s %-15s %-15s\n",
- "position",
- (obj1!=NULL) ? obj1 : " ",
- (obj2!=NULL) ? obj2 : " ",
- "difference",
- "relative");
- parallel_print("------------------------------------------------------------------------\n");
- }
- else
- {
- parallel_print("%-15s %-15s %-15s %-20s\n",
- "position",
- (obj1!=NULL) ? obj1 : " ",
- (obj2!=NULL) ? obj2 : " ",
- "difference");
- parallel_print("------------------------------------------------------------\n");
- }
+ print_header(pp, rank, dims, obj1, obj2);
} /* end print header */
for ( i = 0; i < rank; i++)
diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c
index 7f2a80a..ad9331d 100644
--- a/tools/lib/h5diff_dset.c
+++ b/tools/lib/h5diff_dset.c
@@ -462,8 +462,17 @@ hsize_t diff_datasetid( hid_t did1,
assert(sm_nbytes > 0);
}
+ /* malloc return code should be verified.
+ * If fail, need to handle the error.
+ * This else branch should be recoded as a separate function.
+ * Note that there are many "goto error" within this branch
+ * that fails to address freeing other objects created here.
+ * E.g., sm_space.
+ */
sm_buf1 = malloc((size_t)sm_nbytes);
+ assert(sm_buf1);
sm_buf2 = malloc((size_t)sm_nbytes);
+ assert(sm_buf2);
sm_nelmts = sm_nbytes / p_type_nbytes;
sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
@@ -537,18 +546,11 @@ hsize_t diff_datasetid( hid_t did1,
H5Sclose(sm_space);
/* free */
- if (sm_buf1!=NULL)
- {
- free(sm_buf1);
- sm_buf1=NULL;
- }
- if (sm_buf2!=NULL)
- {
- free(sm_buf2);
- sm_buf2=NULL;
- }
-
- } /* hyperslab read */
+ HDfree(sm_buf1);
+ sm_buf1 = NULL;
+ HDfree(sm_buf2);
+ sm_buf2 = NULL;
+ } /* hyperslab read */
}/*can_compare*/
/*-------------------------------------------------------------------------
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index fb4bd55..55075a0 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -1307,17 +1307,17 @@ h5tools_print_region_data_blocks(hid_t region_space, hid_t region_id,
hsize_t curr_pos;
int jndx;
int type_size;
- hid_t mem_space;
+ hid_t mem_space = -1;
void *region_buf = NULL;
int blkndx;
- hid_t sid1;
+ hid_t sid1 = -1;
/* Get the dataspace of the dataset */
if((sid1 = H5Dget_space(region_id)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed");
/* Allocate space for the dimension array */
- if((dims1 = (hsize_t *) malloc(sizeof(hsize_t) * ndims)) == NULL)
+ if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims");
/* find the dimensions of each data space from the block coordinates */
@@ -1334,15 +1334,15 @@ h5tools_print_region_data_blocks(hid_t region_space, hid_t region_id,
if((type_size = H5Tget_size(type_id)) == 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
- if((region_buf = malloc(type_size * numelem)) == NULL)
+ if((region_buf = HDmalloc(type_size * numelem)) == NULL)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate region buffer");
/* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */
/* 1 2 n 1 2 n */
- if((start = (hsize_t *) malloc(sizeof(hsize_t) * ndims)) == NULL)
+ if((start = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for start");
- if((count = (hsize_t *) malloc(sizeof(hsize_t) * ndims)) == NULL)
+ if((count = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for count");
curr_pos = 0;
@@ -1408,10 +1408,10 @@ h5tools_print_region_data_blocks(hid_t region_space, hid_t region_id,
} /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */
done:
- free(start);
- free(count);
- free(region_buf);
- free(dims1);
+ HDfree(start);
+ HDfree(count);
+ HDfree(region_buf);
+ HDfree(dims1);
if(H5Sclose(mem_space) < 0)
HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
@@ -1648,18 +1648,17 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id,
int indx;
int jndx;
int type_size;
- hid_t mem_space;
- hid_t dtype;
+ hid_t mem_space = -1;
void *region_buf = NULL;
if((type_size = H5Tget_size(type_id)) == 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
- if((region_buf = malloc(type_size * npoints)) == NULL)
+ if((region_buf = HDmalloc(type_size * npoints)) == NULL)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region");
/* Allocate space for the dimension array */
- if((dims1 = (hsize_t *) malloc(sizeof(hsize_t) * ndims)) == NULL)
+ if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims");
dims1[0] = npoints;
@@ -1723,8 +1722,8 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id,
} /* end for (jndx = 0; jndx < npoints; jndx++, region_elmtno++) */
done:
- free(region_buf);
- free(dims1);
+ HDfree(region_buf);
+ HDfree(dims1);
if(H5Sclose(mem_space) < 0)
HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
@@ -1972,7 +1971,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
hsize_t sm_nbytes; /* bytes per stripmine */
hsize_t sm_nelmts; /* elements per stripmine*/
unsigned char *sm_buf = NULL; /* buffer for raw data */
- hid_t sm_space; /* stripmine data space */
+ hid_t sm_space = -1; /* stripmine data space */
hsize_t size_row_block; /* size for blocks along rows */
hsize_t row_counter = 0;
@@ -2025,7 +2024,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
}
assert(sm_nbytes == (hsize_t) ((size_t) sm_nbytes)); /*check for overflow*/
- if((sm_buf = malloc((size_t) sm_nelmts * p_type_nbytes)) == NULL)
+ if((sm_buf = HDmalloc((size_t) sm_nelmts * p_type_nbytes)) == NULL)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for strip-mine");
if((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0)
@@ -2070,7 +2069,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
done:
if(H5Sclose(sm_space) < 0)
HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
- free(sm_buf);
+ HDfree(sm_buf);
}
else
H5E_THROW(SUCCEED, H5E_tools_min_id_g, "nothing to print");
@@ -3379,14 +3378,18 @@ h5tools_print_enum(h5tools_str_t *buffer, hid_t type)
CATCH
- /* Release resources */
- for (i = 0; i < nmembs; i++)
- free(name[i]);
+ if(name) {
+ /* Release resources */
+ for (i = 0; i < nmembs; i++)
+ if(name[i])
+ free(name[i]);
+ free(name);
+ } /* end if */
- free(name);
- free(value);
-
- if(H5Tclose(super) < 0)
+ if(value)
+ free(value);
+
+ if(super >= 0 && H5Tclose(super) < 0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
if (0 == nmembs)