summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c++/src/H5CommonFG.cpp6
-rw-r--r--c++/test/trefer.cpp6
-rw-r--r--src/H5Dchunk.c1
-rw-r--r--src/H5FDfamily.c6
-rw-r--r--src/H5FDsec2.c8
-rw-r--r--src/H5Fsuper_cache.c11
-rw-r--r--src/H5T.c101
-rw-r--r--src/H5Zdeflate.c5
-rw-r--r--src/H5Ztrans.c45
-rw-r--r--test/cmpd_dset.c7
-rw-r--r--test/dsets.c94
-rw-r--r--test/external.c45
-rw-r--r--test/links.c156
-rwxr-xr-xtest/objcopy.c16
-rw-r--r--tools/h5dump/h5dump.c6
-rw-r--r--tools/h5dump/h5dumpgentest.c93
-rw-r--r--tools/h5repack/h5repacktst.c33
-rw-r--r--tools/lib/h5diff_dset.c26
-rw-r--r--tools/lib/h5tools.c55
19 files changed, 429 insertions, 291 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index f9311c6..dd4a419 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -570,8 +570,10 @@ H5std_string CommonFG::getComment( const char* name, size_t bufsize ) const
// if the actual length of the comment is longer than bufsize and bufsize
// was the default value, i.e., not given by the user, then call
- // H5Oget_comment_by_name again with the correct value
- if ((size_t)ret_value > bufsize && bufsize == 256)
+ // H5Oget_comment_by_name again with the correct value.
+ // If the call to H5Oget_comment_by_name returned an error, skip this block
+ // and throw an exception below.
+ if (ret_value >= 0 && (size_t)ret_value > bufsize && bufsize == 256)
{
size_t new_size = ret_value;
delete []comment_C;
diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp
index f17f37a..c4ac93b 100644
--- a/c++/test/trefer.cpp
+++ b/c++/test/trefer.cpp
@@ -217,6 +217,12 @@ static void test_reference_obj(void)
H5std_string read_comment1 = group.getComment(".", 10);
verify_val(read_comment1, write_comment, "Group::getComment", __LINE__, __FILE__);
+ // Test that getComment handles failures gracefully
+ try {
+ H5std_string read_comment_tmp = group.getComment(NULL);
+ }
+ catch (Exception E) {} // We expect this to fail
+
// Close group
group.close();
diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c
index 8788d86..a358320 100644
--- a/src/H5Dchunk.c
+++ b/src/H5Dchunk.c
@@ -2431,6 +2431,7 @@ H5D_chunk_flush_entry(const H5D_t *dset, hid_t dxpl_id, const H5D_dxpl_cache_t *
done:
/* Free the temp buffer only if it's different than the entry chunk */
if(buf != ent->chunk)
+ /* coverity["double_free"] */
H5MM_xfree(buf);
/*
diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c
index 9817270..87e5e84 100644
--- a/src/H5FDfamily.c
+++ b/src/H5FDfamily.c
@@ -818,9 +818,11 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id,
/* Enlarge member array */
if(file->nmembs >= file->amembs) {
unsigned n = MAX(64, 2 * file->amembs);
- H5FD_t **x = (H5FD_t **)H5MM_realloc(file->memb, n * sizeof(H5FD_t *));
+ H5FD_t **x;
- if(!x)
+ HDassert(n > 0);
+ /* coverity["freed_arg"] */
+ if(NULL == (x = (H5FD_t **)H5MM_realloc(file->memb, n * sizeof(H5FD_t *))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to reallocate members")
file->amembs = n;
file->memb = x;
diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c
index 181a153..a030934 100644
--- a/src/H5FDsec2.c
+++ b/src/H5FDsec2.c
@@ -425,9 +425,11 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
ret_value = (H5FD_t*)file;
done:
- if(ret_value==NULL) {
- if(fd>=0)
+ if(NULL == ret_value) {
+ if(fd >= 0)
HDclose(fd);
+ if(file)
+ file = H5FL_FREE(H5FD_sec2_t, file);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -464,7 +466,7 @@ H5FD_sec2_close(H5FD_t *_file)
HSYS_GOTO_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file")
/* Release the file info */
- (void)H5FL_FREE(H5FD_sec2_t, file);
+ file = H5FL_FREE(H5FD_sec2_t, file);
done:
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5Fsuper_cache.c b/src/H5Fsuper_cache.c
index 501e64b..d2aaef8 100644
--- a/src/H5Fsuper_cache.c
+++ b/src/H5Fsuper_cache.c
@@ -111,7 +111,8 @@ H5FL_EXTERN(H5F_super_t);
*-------------------------------------------------------------------------
*/
static H5F_super_t *
-H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, void *udata2/*out*/)
+H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t UNUSED addr, const void UNUSED *udata1,
+ void *udata2/*out*/)
{
H5F_super_t *sblock = NULL; /* File's superblock */
haddr_t base_addr = HADDR_UNDEF; /* Base address of file */
@@ -609,6 +610,11 @@ H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1
ret_value = sblock;
done:
+ /* Release the [possibly partially initialized] superblock on errors */
+ if(!ret_value && sblock)
+ if(H5F_sblock_dest(f, sblock) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTFREE, NULL, "unable to destroy superblock data")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_sblock_load() */
@@ -628,7 +634,8 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5F_super_t *sblock)
+H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t UNUSED addr,
+ H5F_super_t *sblock)
{
herr_t ret_value = SUCCEED;
diff --git a/src/H5T.c b/src/H5T.c
index 4041cd5..64e39d6 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -3816,84 +3816,85 @@ H5T_get_size(const H5T_t *dt)
* Programmer: Robb Matzke
* Wednesday, December 10, 1997
*
- * Modifications:
- * Robb Matzke, 22 Dec 1998
- * Able to compare enumeration data types.
- *
- * Robb Matzke, 20 May 1999
- * Compares bitfields and opaque types.
- *
- * Quincey Koziol, 19 Mar 2005
- * Allow an enumerated datatypes to compare equal, if the "superset"
- * flag is set and dt2 has a superset of the enumerated values in dt1
*-------------------------------------------------------------------------
*/
int
H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
{
unsigned *idx1 = NULL, *idx2 = NULL;
- int ret_value = 0;
+ size_t base_size;
+ hbool_t swapped;
int i, j;
unsigned u;
int tmp;
- hbool_t swapped;
- size_t base_size;
+ int ret_value = 0;
- FUNC_ENTER_NOAPI(H5T_cmp, 0);
+ FUNC_ENTER_NOAPI(H5T_cmp, 0)
+ /* Sanity check */
+ HDassert(dt1);
+ HDassert(dt2);
+
/* the easy case */
- if (dt1 == dt2) HGOTO_DONE(0);
- assert(dt1);
- assert(dt2);
+ if(dt1 == dt2)
+ HGOTO_DONE(0);
/* compare */
- if (dt1->shared->type < dt2->shared->type) HGOTO_DONE(-1);
- if (dt1->shared->type > dt2->shared->type) HGOTO_DONE(1);
-
- if (dt1->shared->size < dt2->shared->size) HGOTO_DONE(-1);
- if (dt1->shared->size > dt2->shared->size) HGOTO_DONE(1);
-
- if (dt1->shared->parent && !dt2->shared->parent) HGOTO_DONE(-1);
- if (!dt1->shared->parent && dt2->shared->parent) HGOTO_DONE(1);
- if (dt1->shared->parent) {
+ if(dt1->shared->type < dt2->shared->type)
+ HGOTO_DONE(-1);
+ if(dt1->shared->type > dt2->shared->type)
+ HGOTO_DONE(1);
+
+ if(dt1->shared->size < dt2->shared->size)
+ HGOTO_DONE(-1);
+ if(dt1->shared->size > dt2->shared->size)
+ HGOTO_DONE(1);
+
+ if(dt1->shared->parent && !dt2->shared->parent)
+ HGOTO_DONE(-1);
+ if(!dt1->shared->parent && dt2->shared->parent)
+ HGOTO_DONE(1);
+ if(dt1->shared->parent) {
tmp = H5T_cmp(dt1->shared->parent, dt2->shared->parent, superset);
- if (tmp<0) HGOTO_DONE(-1);
- if (tmp>0) HGOTO_DONE(1);
- }
+ if(tmp < 0)
+ HGOTO_DONE(-1);
+ if(tmp > 0)
+ HGOTO_DONE(1);
+ } /* end if */
switch(dt1->shared->type) {
case H5T_COMPOUND:
/*
* Compound data types...
*/
- if (dt1->shared->u.compnd.nmembs < dt2->shared->u.compnd.nmembs)
+ if(dt1->shared->u.compnd.nmembs < dt2->shared->u.compnd.nmembs)
HGOTO_DONE(-1);
- if (dt1->shared->u.compnd.nmembs > dt2->shared->u.compnd.nmembs)
+ if(dt1->shared->u.compnd.nmembs > dt2->shared->u.compnd.nmembs)
HGOTO_DONE(1);
/* Build an index for each type so the names are sorted */
- if (NULL==(idx1 = H5MM_malloc(dt1->shared->u.compnd.nmembs * sizeof(unsigned))) ||
- NULL==(idx2 = H5MM_malloc(dt2->shared->u.compnd.nmembs * sizeof(unsigned))))
+ if(NULL == (idx1 = H5MM_malloc(dt1->shared->u.compnd.nmembs * sizeof(unsigned))) ||
+ NULL == (idx2 = H5MM_malloc(dt2->shared->u.compnd.nmembs * sizeof(unsigned))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed");
- for (u=0; u<dt1->shared->u.compnd.nmembs; u++)
+ for(u = 0; u < dt1->shared->u.compnd.nmembs; u++)
idx1[u] = idx2[u] = u;
if(dt1->shared->u.enumer.nmembs > 1) {
- for (i=dt1->shared->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i)
- for (j=0, swapped=FALSE; j<i; j++)
- if (HDstrcmp(dt1->shared->u.compnd.memb[idx1[j]].name,
- dt1->shared->u.compnd.memb[idx1[j+1]].name) > 0) {
+ for(i = dt1->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i)
+ for(j = 0, swapped=FALSE; j < i; j++)
+ if(HDstrcmp(dt1->shared->u.compnd.memb[idx1[j]].name,
+ dt1->shared->u.compnd.memb[idx1[j + 1]].name) > 0) {
tmp = idx1[j];
- idx1[j] = idx1[j+1];
- idx1[j+1] = tmp;
+ idx1[j] = idx1[j + 1];
+ idx1[j + 1] = tmp;
swapped = TRUE;
}
- for (i=dt2->shared->u.compnd.nmembs-1, swapped=TRUE; swapped && i>=0; --i)
- for (j=0, swapped=FALSE; j<i; j++)
- if (HDstrcmp(dt2->shared->u.compnd.memb[idx2[j]].name,
- dt2->shared->u.compnd.memb[idx2[j+1]].name) > 0) {
+ for(i = dt2->shared->u.compnd.nmembs - 1, swapped = TRUE; swapped && i >= 0; --i)
+ for(j = 0, swapped = FALSE; j<i; j++)
+ if(HDstrcmp(dt2->shared->u.compnd.memb[idx2[j]].name,
+ dt2->shared->u.compnd.memb[idx2[j + 1]].name) > 0) {
tmp = idx2[j];
- idx2[j] = idx2[j+1];
- idx2[j+1] = tmp;
+ idx2[j] = idx2[j + 1];
+ idx2[j + 1] = tmp;
swapped = TRUE;
}
} /* end if */
@@ -4212,13 +4213,13 @@ H5T_cmp(const H5T_t *dt1, const H5T_t *dt2, hbool_t superset)
} /* end switch */
done:
- if(idx1!=NULL)
+ if(NULL != idx1)
H5MM_xfree(idx1);
- if(idx2!=NULL)
+ if(NULL != idx2)
H5MM_xfree(idx2);
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5T_cmp() */
/*-------------------------------------------------------------------------
diff --git a/src/H5Zdeflate.c b/src/H5Zdeflate.c
index c0bcd70..c490720 100644
--- a/src/H5Zdeflate.c
+++ b/src/H5Zdeflate.c
@@ -78,6 +78,11 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts,
FUNC_ENTER_NOAPI(H5Z_filter_deflate, 0)
+ /* Sanity check */
+ HDassert(*buf_size > 0);
+ HDassert(buf);
+ HDassert(*buf);
+
/* Check arguments */
if (cd_nelmts!=1 || cd_values[0]>9)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid deflate aggression level")
diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c
index 2b35786..1a6988f 100644
--- a/src/H5Ztrans.c
+++ b/src/H5Ztrans.c
@@ -335,29 +335,29 @@ H5Z_unget_token(H5Z_token *current)
/*-------------------------------------------------------------------------
* Function: H5Z_get_token
+ *
* Purpose: Determine what the next valid H5Z_token is in the expression
* string. The current position within the H5Z_token string is
* kept internal to the H5Z_token and handled by this and the
* unget_H5Z_token function.
+ *
* Return: Succeess: The passed in H5Z_token with a valid tok_type
* field.
* Failure: The passed in H5Z_token but with the tok_type
* field set to ERROR.
+ *
* Programmer: Bill Wendling
* 26. August 2003
- * Modifications:
- * Leon Arber: Added FUNC_ENTER / FUNC_LEAVE pairs
+ *
*-------------------------------------------------------------------------
*/
static H5Z_token *
H5Z_get_token(H5Z_token *current)
{
-
- void* ret_value=current;
+ void *ret_value = current;
FUNC_ENTER_NOAPI(H5Z_get_token, NULL)
-
/* check args */
assert(current);
@@ -463,11 +463,11 @@ H5Z_get_token(H5Z_token *current)
if (current->tok_begin[0] == '\0')
current->tok_type = H5Z_XFORM_END;
- HGOTO_DONE(current);
+ /* Set return value */
+ ret_value = (void *)current;
done:
FUNC_LEAVE_NOAPI(ret_value)
-
}
@@ -498,17 +498,17 @@ H5Z_xform_destroy_parse_tree(H5Z_node *tree)
FUNC_LEAVE_NOAPI_VOID
}
-
/*-------------------------------------------------------------------------
* Function: H5Z_parse
+ *
* Purpose: Entry function for parsing the expression string.
+ *
* Return: Success: Valid H5Z_node ptr to an expression tree.
* NULLure: NULL
+ *
* Programmer: Bill Wendling
* 26. August 2003
- * Modifications:
- * Leon Arber: Added FUNC_ENTER / FUNC_LEAVE pairs
*
*-------------------------------------------------------------------------
*/
@@ -518,11 +518,10 @@ H5Z_xform_parse(const char *expression, H5Z_datval_ptrs* dat_val_pointers)
H5Z_token tok;
void* ret_value;
- FUNC_ENTER_NOAPI_NOFUNC(H5Z_xform_parse)
-
- if (!expression)
- HGOTO_DONE(NULL)
+ FUNC_ENTER_NOAPI(H5Z_xform_parse, NULL)
+ if(!expression)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "No expression provided?")
/* Set up the initial H5Z_token for parsing */
tok.tok_expr = tok.tok_begin = tok.tok_end = expression;
@@ -573,7 +572,7 @@ H5Z_parse_expression(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
if (!new_node) {
H5Z_xform_destroy_parse_tree(expr);
- HGOTO_DONE(expr)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node")
}
new_node->lchild = expr;
@@ -592,7 +591,7 @@ H5Z_parse_expression(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
if (!new_node) {
H5Z_xform_destroy_parse_tree(expr);
- HGOTO_DONE(expr)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node")
}
new_node->lchild = expr;
@@ -643,7 +642,7 @@ static H5Z_node *
H5Z_parse_term(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
{
H5Z_node *term = NULL;
- void* ret_value;
+ H5Z_node *ret_value;
FUNC_ENTER_NOAPI(H5Z_parse_term, NULL);
term = H5Z_parse_factor(current, dat_val_pointers);
@@ -659,7 +658,7 @@ H5Z_parse_term(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
if (!new_node) {
H5Z_xform_destroy_parse_tree(term);
- HGOTO_DONE(term)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node")
}
new_node->lchild = term;
@@ -678,7 +677,7 @@ H5Z_parse_term(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
if (!new_node) {
H5Z_xform_destroy_parse_tree(term);
- HGOTO_DONE(term)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node")
}
new_node->lchild = term;
@@ -744,7 +743,7 @@ H5Z_parse_factor(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
factor = H5Z_new_node(H5Z_XFORM_INTEGER);
if (!factor)
- HGOTO_DONE(factor)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node")
sscanf(current->tok_begin, "%ld", &factor->value.int_val);
break;
@@ -752,7 +751,7 @@ H5Z_parse_factor(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
factor = H5Z_new_node(H5Z_XFORM_FLOAT);
if (!factor)
- HGOTO_DONE(factor)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node")
sscanf(current->tok_begin, "%lf", &factor->value.float_val);
break;
@@ -760,7 +759,7 @@ H5Z_parse_factor(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
factor = H5Z_new_node(H5Z_XFORM_SYMBOL);
if (!factor)
- HGOTO_DONE(factor)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node")
factor->value.dat_val = &(dat_val_pointers->ptr_dat_val[dat_val_pointers->num_ptrs]);
dat_val_pointers->num_ptrs++;
@@ -770,7 +769,7 @@ H5Z_parse_factor(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
factor = H5Z_parse_expression(current, dat_val_pointers);
if (!factor)
- HGOTO_DONE(factor)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Unable to allocate new node")
current = H5Z_get_token(current);
diff --git a/test/cmpd_dset.c b/test/cmpd_dset.c
index b154f51..d565e82 100644
--- a/test/cmpd_dset.c
+++ b/test/cmpd_dset.c
@@ -1998,9 +1998,10 @@ error:
static int
test_ooo_order(char *filename)
{
- hid_t file; /* File ID */
- hid_t dtype, dtype_tmp; /* Datatype IDs */
- H5T_t *dt; /* Datatype pointer */
+ hid_t file = -1; /* File ID */
+ hid_t dtype = -1; /* Datatype IDs */
+ hid_t dtype_tmp = -1; /* Temp Datatype ID */
+ H5T_t *dt = NULL; /* Datatype pointer */
TESTING("that compound member insertion order is preserved")
diff --git a/test/dsets.c b/test/dsets.c
index 0522bd0..58fa2c8 100644
--- a/test/dsets.c
+++ b/test/dsets.c
@@ -710,7 +710,9 @@ test_max_compact(hid_t fapl)
compact_size = (SIXTY_FOUR_KB-64)/sizeof(int);
wbuf = (int*)HDmalloc(sizeof(int)*(size_t)compact_size);
+ assert(wbuf);
rbuf = (int*)HDmalloc(sizeof(int)*(size_t)compact_size);
+ assert(rbuf);
n=0;
for(i=0; i<(int)compact_size; i++)
@@ -767,8 +769,9 @@ test_max_compact(hid_t fapl)
if(H5Dclose(dataset) < 0) goto error;
if(H5Fclose(file) < 0) goto error;
HDfree(wbuf);
+ wbuf = NULL;
HDfree(rbuf);
-
+ rbuf = NULL;
/* Test compact dataset of size 64KB */
@@ -802,6 +805,19 @@ test_max_compact(hid_t fapl)
return 0;
error:
+ if(wbuf)
+ HDfree(wbuf);
+ if(rbuf)
+ HDfree(rbuf);
+
+ H5E_BEGIN_TRY {
+ /* Close file */
+ H5Sclose(space);
+ H5Pclose(plist);
+ H5Fclose(file);
+ H5Dclose(dataset);
+ } H5E_END_TRY;
+
return -1;
}
@@ -973,10 +989,10 @@ error:
static herr_t
test_tconv(hid_t file)
{
- char *out=NULL, *in=NULL;
- int i;
+ char *out = NULL, *in = NULL;
hsize_t dims[1];
- hid_t space, dataset;
+ hid_t space = -1, dataset = -1;
+ int i;
out = (char *)HDmalloc((size_t)(4 * 1000 * 1000));
HDassert(out);
@@ -987,11 +1003,11 @@ test_tconv(hid_t file)
/* Initialize the dataset */
for(i = 0; i < 1000000; i++) {
- out[i*4+0] = 0x11;
- out[i*4+1] = 0x22;
- out[i*4+2] = 0x33;
- out[i*4+3] = 0x44;
- }
+ out[i * 4 + 0] = 0x11;
+ out[i * 4 + 1] = 0x22;
+ out[i * 4 + 2] = 0x33;
+ out[i * 4 + 3] = 0x44;
+ } /* end for */
/* Create the data space */
dims[0] = 1000000;
@@ -1008,27 +1024,39 @@ test_tconv(hid_t file)
/* Read data with byte order conversion */
if(H5Dread(dataset, H5T_STD_I32BE, H5S_ALL, H5S_ALL, H5P_DEFAULT, in) < 0)
- goto error;
+ goto error;
/* Check */
for(i = 0; i < 1000000; i++) {
- if(in[4*i+0]!=out[4*i+3] ||
- in[4*i+1]!=out[4*i+2] ||
- in[4*i+2]!=out[4*i+1] ||
- in[4*i+3]!=out[4*i+0]) {
- H5_FAILED();
- puts(" Read with byte order conversion failed.");
- goto error;
- }
+ if(in[4 * i + 0] != out[4 * i + 3] ||
+ in[4 * i + 1] != out[4 * i + 2] ||
+ in[4 * i + 2] != out[4 * i + 1] ||
+ in[4 * i + 3] != out[4 * i + 0]) {
+ H5_FAILED();
+ puts(" Read with byte order conversion failed.");
+ goto error;
+ }
}
if(H5Dclose(dataset) < 0) goto error;
- free (out);
- free (in);
+ if(H5Sclose(space) < 0) goto error;
+ HDfree(out);
+ HDfree(in);
+
puts(" PASSED");
return 0;
- error:
+error:
+ if(out)
+ HDfree(out);
+ if(in)
+ HDfree(in);
+
+ H5E_BEGIN_TRY {
+ H5Dclose(dataset);
+ H5Sclose(space);
+ } H5E_END_TRY;
+
return -1;
}
@@ -1241,19 +1269,19 @@ filter_corrupt(unsigned int flags, size_t cd_nelmts,
const unsigned int *cd_values, size_t nbytes,
size_t *buf_size, void **buf)
{
- size_t ret_value = 0;
+ void *data;
unsigned char *dst = (unsigned char*)(*buf);
unsigned int offset;
unsigned int length;
unsigned int value;
- void *data;
+ size_t ret_value = 0;
- if(cd_nelmts!=3 || !cd_values)
+ if(cd_nelmts != 3 || !cd_values)
return 0;
offset = cd_values[0];
length = cd_values[1];
value = cd_values[2];
- if(offset>nbytes || (offset+length)>nbytes || length<sizeof(unsigned int))
+ if(offset > nbytes || (offset + length) > nbytes || length < sizeof(unsigned int))
return 0;
data = HDmalloc((size_t)length);
@@ -1261,15 +1289,19 @@ filter_corrupt(unsigned int flags, size_t cd_nelmts,
if(flags & H5Z_FLAG_REVERSE) { /* Varify data is actually corrupted during read */
dst += offset;
- if(HDmemcmp(data, dst, (size_t)length)!=0) return 0;
- *buf_size = nbytes;
- ret_value = nbytes;
- } else { /* Write corrupted data */
+ if(HDmemcmp(data, dst, (size_t)length) != 0)
+ ret_value = 0;
+ else {
+ *buf_size = nbytes;
+ ret_value = nbytes;
+ } /* end else */
+ } /* end if */
+ else { /* Write corrupted data */
dst += offset;
HDmemcpy(dst, data, (size_t)length);
*buf_size = nbytes;
- ret_value = *buf_size;
- }
+ ret_value = *buf_size;
+ } /* end else */
if(data)
HDfree(data);
diff --git a/test/external.c b/test/external.c
index 25d465c..b3831ad 100644
--- a/test/external.c
+++ b/test/external.c
@@ -58,21 +58,23 @@ same_contents (const char *name1, const char *name2)
fd1 = HDopen(name1, O_RDONLY, 0666);
fd2 = HDopen(name2, O_RDONLY, 0666);
- assert (fd1>=0 && fd2>=0);
-
- while (1) {
- n1 = HDread(fd1, buf1, sizeof(buf1));
- n2 = HDread(fd2, buf2, sizeof(buf2));
- assert (n1>=0 && (size_t)n1<=sizeof(buf1));
- assert (n2>=0 && (size_t)n2<=sizeof(buf2));
- assert (n1==n2);
-
- if (n1<=0 && n2<=0) break;
- if (memcmp (buf1, buf2, (size_t)n1)) {
- HDclose(fd1);
- HDclose(fd2);
- return 0;
- }
+ assert(fd1 >= 0 && fd2 >= 0);
+
+ while(1) {
+ /* Asserts will catch negative return values */
+ n1 = HDread(fd1, buf1, sizeof(buf1));
+ n2 = HDread(fd2, buf2, sizeof(buf2));
+ assert(n1 >= 0 && (size_t)n1 <= sizeof(buf1));
+ assert(n2 >= 0 && (size_t)n2 <= sizeof(buf2));
+ assert(n1 == n2);
+
+ if(n1 == 0 && n2 == 0)
+ break;
+ if(HDmemcmp(buf1, buf2, (size_t)n1)) {
+ HDclose(fd1);
+ HDclose(fd2);
+ return 0;
+ }
}
HDclose(fd1);
HDclose(fd2);
@@ -838,10 +840,13 @@ test_3 (hid_t fapl)
static int
test_4 (hid_t fapl)
{
- hid_t fid, gid, xid, xid2;
- char filename[1024]; /*file name */
- char pathname[1024];
- char *srcdir = getenv("srcdir"); /*where the src code is located*/
+ hid_t fid = -1;
+ hid_t gid = -1;
+ hid_t xid = -1;
+ hid_t xid2 = -1;
+ char filename[1024]; /*file name */
+ char pathname[1024];
+ char *srcdir = getenv("srcdir"); /*where the src code is located*/
TESTING("opening external link twice");
@@ -911,7 +916,7 @@ test_4 (hid_t fapl)
H5Gclose(gid);
H5Gclose(xid);
H5Gclose(xid2);
- H5Fclose(fid);
+ H5Fclose(fid);
} H5E_END_TRY;
return 1;
}
diff --git a/test/links.c b/test/links.c
index 8612180..84d2542 100644
--- a/test/links.c
+++ b/test/links.c
@@ -3571,8 +3571,8 @@ external_set_elink_fapl1(hid_t fapl, hbool_t new_format)
filename2B[NAME_BUF_SIZE],
tmpname[NAME_BUF_SIZE],
cwdpath[NAME_BUF_SIZE];
- hid_t fam_fapl, multi_fapl;
- hid_t lapl_idA, lapl_idB;
+ hid_t fam_fapl=-1, multi_fapl=-1;
+ hid_t lapl_idA=-1, lapl_idB=-1;
H5FD_mem_t mt, memb_map[H5FD_MEM_NTYPES];
hid_t memb_fapl[H5FD_MEM_NTYPES];
char sv[H5FD_MEM_NTYPES][500];
@@ -3769,11 +3769,11 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format)
{
hid_t fid = (-1); /* File ID */
hid_t gid = (-1); /* Group IDs */
+ hid_t core_fapl = -1, space = -1, dset = -1, did = -1, dapl_id = -1, dcpl = -1;
char filename1[NAME_BUF_SIZE],
filename2[NAME_BUF_SIZE],
tmpname[NAME_BUF_SIZE],
cwdpath[NAME_BUF_SIZE];
- hid_t core_fapl, space, dset, did, dapl_id, dcpl;
hsize_t dims[2];
int points[NUM40][NUM40];
h5_stat_size_t filesize, new_filesize;
@@ -3806,8 +3806,8 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format)
h5_fixname(FILENAME[39], core_fapl, filename2, sizeof filename2);
/* Create the target file to be a "core" file */
- if((fid=H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, core_fapl)) < 0) TEST_ERROR
- if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
+ if((fid = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, core_fapl)) < 0) TEST_ERROR
+ if((gid = H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
dims[0] = NUM40;
dims[1] = NUM40;
@@ -3848,8 +3848,7 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format)
/* try to open the external linked target dataset */
did = H5Dopen2(fid, "ext_link", dapl_id);
-
- if (did < 0) {
+ if(did < 0) {
H5_FAILED();
puts(" Should succeed in opening the target dataset");
goto error;
@@ -3871,7 +3870,7 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format)
new_filesize = h5_get_file_size(filename2, core_fapl);
/* the file size should remain the same since there is no backing store */
- if (new_filesize != filesize) TEST_ERROR
+ if(new_filesize != filesize) TEST_ERROR
if(H5Pclose(core_fapl) < 0) TEST_ERROR
@@ -3885,8 +3884,9 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format)
H5Dclose(dset);
H5Pclose(core_fapl);
H5Pclose(dapl_id);
- H5Dclose (did);
- H5Fclose (fid);
+ H5Dclose(did);
+ H5Gclose(gid);
+ H5Fclose(fid);
} H5E_END_TRY;
return -1;
} /* end external_set_elink_fapl2() */
@@ -3926,8 +3926,8 @@ external_set_elink_fapl2(hid_t fapl, hbool_t new_format)
static int
external_set_elink_fapl3(hbool_t new_format)
{
- hid_t core_fapl, stdio_fapl;
- hid_t lapl_id, new_lapl_id, l_fapl, out_fapl;
+ hid_t core_fapl = -1, stdio_fapl = -1;
+ hid_t lapl_id = -1, new_lapl_id = -1, l_fapl = -1, out_fapl;
int ret;
if(new_format)
@@ -3950,43 +3950,43 @@ external_set_elink_fapl3(hbool_t new_format)
/* Verify that the driver for the link's fapl is the "stdio" driver */
if((l_fapl = H5Pget_elink_fapl(lapl_id)) < 0) TEST_ERROR
- if (H5Pget_driver(l_fapl) != H5FD_STDIO) TEST_ERROR
- if (H5Pclose(l_fapl) < 0) TEST_ERROR
+ if(H5Pget_driver(l_fapl) != H5FD_STDIO) TEST_ERROR
+ if(H5Pclose(l_fapl) < 0) TEST_ERROR
/* Set file access property list for link access to use the "core" driver */
if(H5Pset_elink_fapl(lapl_id, core_fapl) < 0) TEST_ERROR
/* Make a copy of the link access property */
- if ((new_lapl_id = H5Pcopy(lapl_id)) < 0) TEST_ERROR
+ if((new_lapl_id = H5Pcopy(lapl_id)) < 0) TEST_ERROR
/* get the fapl set in lapl_id */
- if (H5Pget(lapl_id, "external link fapl", &out_fapl) < 0) TEST_ERROR
- if (H5Pclose(lapl_id) < 0) TEST_ERROR
+ if(H5Pget(lapl_id, "external link fapl", &out_fapl) < 0) TEST_ERROR
+ if(H5Pclose(lapl_id) < 0) TEST_ERROR
/* Try closing out_fapl should fail since H5Pclose(lapl_id) should also close its fapl */
H5E_BEGIN_TRY {
ret = H5Pclose(out_fapl);
} H5E_END_TRY;
- if (ret != FAIL) TEST_ERROR
+ if(ret != FAIL) TEST_ERROR
/* Verify that the driver for the copied link's fapl is the "core" driver */
if((l_fapl = H5Pget_elink_fapl(new_lapl_id)) < 0) TEST_ERROR
- if (H5Pget_driver(l_fapl) != H5FD_CORE) TEST_ERROR
+ if(H5Pget_driver(l_fapl) != H5FD_CORE) TEST_ERROR
/* get the fapl set in new_lapl_id */
- if (H5Pget(new_lapl_id, "external link fapl", &out_fapl) < 0) TEST_ERROR
- if (H5Premove(new_lapl_id, "external link fapl") < 0) TEST_ERROR
+ if(H5Pget(new_lapl_id, "external link fapl", &out_fapl) < 0) TEST_ERROR
+ if(H5Premove(new_lapl_id, "external link fapl") < 0) TEST_ERROR
/* Try closing out_fapl should fail since the property is removed from new_lapl_id */
H5E_BEGIN_TRY {
ret = H5Pclose(out_fapl);
} H5E_END_TRY;
- if (ret != FAIL) TEST_ERROR
+ if(ret != FAIL) TEST_ERROR
- if (H5Pclose(l_fapl) < 0) TEST_ERROR
- if (H5Pclose(new_lapl_id) < 0) TEST_ERROR
- if (H5Pclose(core_fapl) < 0) TEST_ERROR
- if (H5Pclose(stdio_fapl) < 0) TEST_ERROR
+ if(H5Pclose(l_fapl) < 0) TEST_ERROR
+ if(H5Pclose(new_lapl_id) < 0) TEST_ERROR
+ if(H5Pclose(core_fapl) < 0) TEST_ERROR
+ if(H5Pclose(stdio_fapl) < 0) TEST_ERROR
PASSED();
return 0;
@@ -4021,7 +4021,7 @@ external_set_elink_fapl3(hbool_t new_format)
static int
external_set_elink_acc_flags(hid_t fapl, hbool_t new_format)
{
- hid_t file1, file2, group, subgroup, gapl;
+ hid_t file1 = -1, file2 = -1, group = -1, subgroup = -1, gapl = -1;
char filename1[NAME_BUF_SIZE],
filename2[NAME_BUF_SIZE];
unsigned flags;
@@ -4034,70 +4034,70 @@ external_set_elink_acc_flags(hid_t fapl, hbool_t new_format)
/* Create parent and target files, and external link */
h5_fixname(FILENAME[40], fapl, filename1, sizeof filename1);
h5_fixname(FILENAME[41], fapl, filename2, sizeof filename2);
- if ((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR
- if ((file2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR
- if (H5Lcreate_external(filename2, "/", file1, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
+ if((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR
+ if((file2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR
+ if(H5Lcreate_external(filename2, "/", file1, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
/* Close file2, leave file1 open (should be read-write) */
- if (H5Fclose(file2) < 0) TEST_ERROR
+ if(H5Fclose(file2) < 0) TEST_ERROR
/* Create new gapl, and set elink access flags to be H5F_ACC_RDONLY */
- if ((gapl = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR
- if (H5Pset_elink_acc_flags(gapl, H5F_ACC_RDONLY) < 0) TEST_ERROR
+ if((gapl = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR
+ if(H5Pset_elink_acc_flags(gapl, H5F_ACC_RDONLY) < 0) TEST_ERROR
/* Verify "get" routine functionality */
- if (H5Pget_elink_acc_flags(gapl, &flags) < 0) TEST_ERROR
- if (flags != H5F_ACC_RDONLY) TEST_ERROR
+ if(H5Pget_elink_acc_flags(gapl, &flags) < 0) TEST_ERROR
+ if(flags != H5F_ACC_RDONLY) TEST_ERROR
/* Attempt to create a group through the external link using gapl (should fail) */
H5E_BEGIN_TRY {
group = H5Gcreate2(file1, "/ext_link/group", H5P_DEFAULT, H5P_DEFAULT, gapl);
} H5E_END_TRY;
- if (group != FAIL) TEST_ERROR
+ if(group != FAIL) TEST_ERROR
/* Close file1 and reopen with read only access */
- if (H5Fclose(file1) < 0) TEST_ERROR
- if ((file1 = H5Fopen(filename1, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR
+ if(H5Fclose(file1) < 0) TEST_ERROR
+ if((file1 = H5Fopen(filename1, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR
/* Set elink access flags on gapl to be H5F_ACC_RDWR */
- if (H5Pset_elink_acc_flags(gapl, H5F_ACC_RDWR) < 0) TEST_ERROR
+ if(H5Pset_elink_acc_flags(gapl, H5F_ACC_RDWR) < 0) TEST_ERROR
/* Create a group through the external link using gapl (should succeed) */
- if ((group = H5Gcreate2(file1, "/ext_link/group", H5P_DEFAULT, H5P_DEFAULT, gapl)) < 0) TEST_ERROR
+ if((group = H5Gcreate2(file1, "/ext_link/group", H5P_DEFAULT, H5P_DEFAULT, gapl)) < 0) TEST_ERROR
/* Unset elink access flags on gapl */
- if (H5Pset_elink_acc_flags(gapl, H5F_ACC_DEFAULT) < 0) TEST_ERROR
+ if(H5Pset_elink_acc_flags(gapl, H5F_ACC_DEFAULT) < 0) TEST_ERROR
/* Attempt to create a group through the external link using gapl (should fail) */
H5E_BEGIN_TRY {
subgroup = H5Gcreate2(file1, "/ext_link/group/subgroup", H5P_DEFAULT, H5P_DEFAULT, gapl);
} H5E_END_TRY;
- if (subgroup != FAIL) TEST_ERROR
+ if(subgroup != FAIL) TEST_ERROR
/* Close file1 and group */
- if (H5Gclose(group) < 0) TEST_ERROR
- if (H5Fclose(file1) < 0) TEST_ERROR
+ if(H5Gclose(group) < 0) TEST_ERROR
+ if(H5Fclose(file1) < 0) TEST_ERROR
/* Verify that H5Fcreate and H5Fopen reject H5F_ACC_DEFAULT */
H5E_BEGIN_TRY {
file1 = H5Fcreate(filename1, H5F_ACC_DEFAULT, H5P_DEFAULT, fapl);
} H5E_END_TRY;
- if (file1 != FAIL) TEST_ERROR
+ if(file1 != FAIL) TEST_ERROR
H5E_BEGIN_TRY {
file1 = H5Fcreate(filename1, H5F_ACC_TRUNC | H5F_ACC_DEFAULT, H5P_DEFAULT, fapl);
} H5E_END_TRY;
- if (file1 != FAIL) TEST_ERROR
+ if(file1 != FAIL) TEST_ERROR
H5E_BEGIN_TRY {
file1 = H5Fopen(filename1, H5F_ACC_DEFAULT, fapl);
} H5E_END_TRY;
- if (file1 != FAIL) TEST_ERROR
+ if(file1 != FAIL) TEST_ERROR
H5E_BEGIN_TRY {
file1 = H5Fopen(filename1, H5F_ACC_RDWR | H5F_ACC_DEFAULT, fapl);
} H5E_END_TRY;
- if (file1 != FAIL) TEST_ERROR
+ if(file1 != FAIL) TEST_ERROR
/* Close gapl */
- if (H5Pclose(gapl) < 0) TEST_ERROR
+ if(H5Pclose(gapl) < 0) TEST_ERROR
PASSED();
return 0;
@@ -4171,7 +4171,7 @@ external_set_elink_cb_cb(const char *parent_file, const char *parent_group,
static int
external_set_elink_cb(hid_t fapl, hbool_t new_format)
{
- hid_t file1, file2, group, gapl, fam_fapl, ret_fapl, base_driver;
+ hid_t file1 = -1, file2 = -1, group = -1, gapl = -1, fam_fapl = -1, ret_fapl = -1, base_driver;
set_elink_cb_t op_data,
*op_data_p;
H5L_elink_traverse_t cb;
@@ -4204,44 +4204,44 @@ external_set_elink_cb(hid_t fapl, hbool_t new_format)
/* Create parent and target files, group, and external link */
h5_fixname(FILENAME[42], fapl, filename1, sizeof filename1);
h5_fixname(FILENAME[43], fam_fapl, filename2, sizeof filename2);
- if ((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR
- if ((file2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fam_fapl)) < 0) TEST_ERROR
- if ((group = H5Gcreate2(file1, "group1",H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
- if (H5Lcreate_external(filename2, "/", group, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
+ if((file1 = H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR
+ if((file2 = H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fam_fapl)) < 0) TEST_ERROR
+ if((group = H5Gcreate2(file1, "group1",H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
+ if(H5Lcreate_external(filename2, "/", group, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
/* Close files and group */
- if (H5Fclose(file1) < 0) TEST_ERROR
- if (H5Fclose(file2) < 0) TEST_ERROR
- if (H5Gclose(group) < 0) TEST_ERROR
+ if(H5Fclose(file1) < 0) TEST_ERROR
+ if(H5Fclose(file2) < 0) TEST_ERROR
+ if(H5Gclose(group) < 0) TEST_ERROR
/* Create new gapl, and set elink callback */
- if ((gapl = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR
- if (H5Pset_elink_cb(gapl, external_set_elink_cb_cb, &op_data) < 0) TEST_ERROR
+ if((gapl = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR
+ if(H5Pset_elink_cb(gapl, external_set_elink_cb_cb, &op_data) < 0) TEST_ERROR
/* Verify "get" routine functionality */
- if (H5Pget_elink_cb(gapl, &cb, (void **) &op_data_p) < 0) TEST_ERROR
- if (cb != external_set_elink_cb_cb) TEST_ERROR
- if (op_data_p != &op_data) TEST_ERROR
+ if(H5Pget_elink_cb(gapl, &cb, (void **) &op_data_p) < 0) TEST_ERROR
+ if(cb != external_set_elink_cb_cb) TEST_ERROR
+ if(op_data_p != &op_data) TEST_ERROR
/* Open file1 with read only access */
- if ((file1 = H5Fopen(filename1, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR
+ if((file1 = H5Fopen(filename1, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR
/* Create a group through the external link using gapl */
- if ((group = H5Gcreate2(file1, "/group1/ext_link/group2", H5P_DEFAULT, H5P_DEFAULT, gapl)) < 0) TEST_ERROR
+ if((group = H5Gcreate2(file1, "/group1/ext_link/group2", H5P_DEFAULT, H5P_DEFAULT, gapl)) < 0) TEST_ERROR
/* Verify that the correct parameters have been set on file2 (somewhat
* redundant as the library would be unable to create the group otherwise)
*/
- if ((file2 = H5Iget_file_id(group)) < 0) TEST_ERROR
- if (H5Fget_intent(file2, &flags) < 0) TEST_ERROR
- if (!(flags & H5F_ACC_RDWR)) TEST_ERROR
- if ((ret_fapl = H5Fget_access_plist(file2)) < 0) TEST_ERROR
- if (H5FD_FAMILY != H5Pget_driver(ret_fapl)) TEST_ERROR
-
- if (H5Gclose(group) < 0) TEST_ERROR
- if (H5Fclose(file2) < 0) TEST_ERROR
- if (H5Pclose(ret_fapl) < 0) TEST_ERROR
- if (H5Pclose(fam_fapl) < 0) TEST_ERROR
+ if((file2 = H5Iget_file_id(group)) < 0) TEST_ERROR
+ if(H5Fget_intent(file2, &flags) < 0) TEST_ERROR
+ if(!(flags & H5F_ACC_RDWR)) TEST_ERROR
+ if((ret_fapl = H5Fget_access_plist(file2)) < 0) TEST_ERROR
+ if(H5FD_FAMILY != H5Pget_driver(ret_fapl)) TEST_ERROR
+
+ if(H5Gclose(group) < 0) TEST_ERROR
+ if(H5Fclose(file2) < 0) TEST_ERROR
+ if(H5Pclose(ret_fapl) < 0) TEST_ERROR
+ if(H5Pclose(fam_fapl) < 0) TEST_ERROR
/* Modify the user data structure to cause the callback to fail next time */
op_data.code = 1;
@@ -4250,7 +4250,7 @@ external_set_elink_cb(hid_t fapl, hbool_t new_format)
H5E_BEGIN_TRY {
group = H5Gopen2(file1, "/group1/ext_link/group2", gapl);
} H5E_END_TRY;
- if (group != FAIL) TEST_ERROR
+ if(group != FAIL) TEST_ERROR
/* Modify the user data structure to cause the callback to return invalid flags */
op_data.code = 2;
@@ -4259,11 +4259,11 @@ external_set_elink_cb(hid_t fapl, hbool_t new_format)
H5E_BEGIN_TRY {
group = H5Gopen2(file1, "/group1/ext_link/group2", gapl);
} H5E_END_TRY;
- if (group != FAIL) TEST_ERROR
+ if(group != FAIL) TEST_ERROR
/* Close */
- if (H5Fclose(file1) < 0) TEST_ERROR
- if (H5Pclose(gapl) < 0) TEST_ERROR
+ if(H5Fclose(file1) < 0) TEST_ERROR
+ if(H5Pclose(gapl) < 0) TEST_ERROR
PASSED();
return 0;
diff --git a/test/objcopy.c b/test/objcopy.c
index 50dabcc..00cc5bf 100755
--- a/test/objcopy.c
+++ b/test/objcopy.c
@@ -713,7 +713,9 @@ compare_attribute(hid_t aid, hid_t aid2, hid_t pid, const void *wbuf, hid_t obj_
/* Release raw data buffers */
HDfree(rbuf);
+ rbuf = NULL;
HDfree(rbuf2);
+ rbuf2 = NULL;
/* close the source dataspace */
if(H5Sclose(sid) < 0) TEST_ERROR
@@ -730,11 +732,11 @@ compare_attribute(hid_t aid, hid_t aid2, hid_t pid, const void *wbuf, hid_t obj_
return TRUE;
error:
+ if(rbuf)
+ HDfree(rbuf);
+ if(rbuf2)
+ HDfree(rbuf2);
H5E_BEGIN_TRY {
- if(rbuf)
- HDfree(rbuf);
- if(rbuf2)
- HDfree(rbuf2);
H5Sclose(sid2);
H5Sclose(sid);
H5Tclose(tid2);
@@ -7247,9 +7249,11 @@ static int
test_copy_dataset_contig_cmpd_vl(hid_t fcpl_src, hid_t fcpl_dst, hid_t fapl)
{
hid_t fid_src = -1, fid_dst = -1; /* File IDs */
- hid_t tid = -1, tid2; /* Datatype IDs */
+ hid_t tid = -1; /* Datatype ID */
+ hid_t tid2 = -1; /* Datatype ID */
hid_t sid = -1; /* Dataspace ID */
- hid_t did = -1, did2 = -1; /* Dataset IDs */
+ hid_t did = -1; /* Dataset ID */
+ hid_t did2 = -1; /* Dataset ID */
unsigned int i, j; /* Local index variables */
hsize_t dim1d[1]; /* Dataset dimensions */
cmpd_vl_t buf[DIM_SIZE_1]; /* Buffer for writing data */
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 2ddc0bf..ddee2c3 100644
--- a/tools/h5dump/h5dumpgentest.c
+++ b/tools/h5dump/h5dumpgentest.c
@@ -5802,12 +5802,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];
@@ -5865,14 +5865,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);
@@ -5885,11 +5892,11 @@ out:
H5Pclose(dcpl);
H5Sclose(f_sid);
H5Sclose(m_sid);
+ H5Tclose(tid);
H5Dclose(did);
H5Fclose(fid);
} H5E_END_TRY;
return;
-
}
@@ -5936,10 +5943,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;
@@ -5965,37 +5972,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;
/*-------------------------------------------------------------------------
@@ -6010,45 +6025,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;
@@ -6076,15 +6102,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" };
@@ -6137,10 +6163,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;
/*-------------------------------------------------------------------------
@@ -6161,10 +6189,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;
@@ -6185,11 +6215,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
@@ -6208,12 +6239,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
@@ -6235,11 +6266,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
@@ -6261,11 +6293,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
@@ -6283,12 +6316,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
@@ -6296,15 +6329,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/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c
index e36a8dc..3dcde22 100644
--- a/tools/h5repack/h5repacktst.c
+++ b/tools/h5repack/h5repacktst.c
@@ -4162,9 +4162,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;
@@ -4246,6 +4246,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_BITFIELD
@@ -4275,6 +4276,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_OPAQUE
@@ -4301,6 +4303,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_COMPOUND
@@ -4338,6 +4341,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_REFERENCE
@@ -4386,6 +4390,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_VLEN
@@ -4430,10 +4435,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
@@ -4468,6 +4476,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_INTEGER and H5T_FLOAT
@@ -4545,6 +4554,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_BITFIELD
@@ -4577,6 +4587,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_OPAQUE
@@ -4604,6 +4615,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_COMPOUND
@@ -4639,6 +4651,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_REFERENCE
@@ -4693,6 +4706,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_VLEN
@@ -4742,10 +4756,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
@@ -4788,6 +4805,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_INTEGER and H5T_FLOAT
@@ -4907,6 +4925,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_BITFIELD
@@ -4961,6 +4980,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_OPAQUE
@@ -4974,6 +4994,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_COMPOUND
@@ -5064,6 +5085,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_REFERENCE
@@ -5148,6 +5170,7 @@ int write_attr_in(hid_t loc_id,
goto out;
if (H5Tclose(tid) < 0)
goto out;
+ tid = -1;
/*-------------------------------------------------------------------------
* H5T_VLEN
@@ -5202,10 +5225,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
@@ -5239,6 +5265,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_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)