From 34d14bdf89d63023dfeb5ff471b71e5b591faa31 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 10 Dec 2009 07:36:56 -0500 Subject: [svn-r17980] Description: Bring Coverity changes into the trunk: (also other minor cleanups) r17955: Fix Coverity item 24. Add missing error condition to H5AC_ext_config_2_int_config. r17956: Fix Coverity item 24. Improve error checking in H5A_compact_build_table_cb. r17957: Fix Coverity item 150. Fix warning in H5A_compact_build_table_cb. r17958: Fix Coverity item 117. Fix error handling in H5B_shared_new. r17959: Fix Coverity item 209. Added an assertion for leaf->shared in H5B2_cache_leaf_dest. r17960: Fix Coverity item 208. Added an assertion for internal->shared in H5B2_cache_internal_dest. r17961: Fix Coverity item 89. Reworked the code to avoid array overrun in H5C__autoadjust__ageout__insert_new_marker. r17962: Fix for coverity Resource_leak 195,203,204,205. r17963: Fix Coverity item 44. Prevented potential NULL dereference in H5D_btree_debug. r17964: Fix Coverity issues #197, 198 & 199: memory not being released. (Also clean up other resource leaks in nearby and/or similar code). r17965: Fix Coverity issue #151: release resources on error r17966: Fix Coverity issue #187: Remove leftover code remnant from prior bugfix which was causing resource leak of open files. r17967: Fixed Coverity issues # 193 & 194. Removed unnecessary memory allocation and added comparison of length of path parameter to the size of the destination buffer in h5import.h/h5import.c. r17968: Fix Coverity item 144. Fixed memory leak on error in H5D_chunk_copy. r17969: Fix for coverity Resource_leak #196. r17970: Coverity 167-173: Initialized pointer of buffers. In error handling, closed types and free memory. Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode Mac OS X/32 10.6.2 (amazon) in debug mode Mac OS X/32 10.6.2 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode --- src/H5AC.c | 3 +- src/H5Aint.c | 31 +- src/H5B.c | 19 +- src/H5C.c | 6 +- src/H5Dbtree.c | 5 +- src/H5Dchunk.c | 14 +- src/H5Oattr.c | 15 + test/btree2.c | 4 +- test/dsets.c | 2 +- test/dt_arith.c | 2 +- test/dtypes.c | 2 +- test/hyperslab.c | 2 +- test/istore.c | 2 +- test/ntypes.c | 1315 +++++++++++++++++++++--------------- test/pool.c | 2 +- test/theap.c | 2 +- test/tskiplist.c | 2 +- test/ttst.c | 2 +- test/tunicode.c | 2 +- test/unlink.c | 76 ++- test/vfd.c | 5 - tools/h5import/h5import.c | 25 +- tools/h5import/h5import.h | 3 +- tools/h5jam/h5jamgentest.c | 2 + tools/h5repack/h5repack.c | 22 +- tools/h5repack/h5repack_opttable.c | 18 +- tools/h5repack/h5repacktst.c | 16 +- 27 files changed, 964 insertions(+), 635 deletions(-) diff --git a/src/H5AC.c b/src/H5AC.c index 9273c0c..cbe4dd0 100644 --- a/src/H5AC.c +++ b/src/H5AC.c @@ -3637,7 +3637,8 @@ H5AC_ext_config_2_int_config(H5AC_cache_config_t * ext_conf_ptr, if ( ( ext_conf_ptr == NULL ) || ( ext_conf_ptr->version != H5AC__CURR_CACHE_CONFIG_VERSION ) || ( int_conf_ptr == NULL ) ) { - + HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, \ + "Bad ext_conf_ptr or inf_conf_ptr on entry.") } int_conf_ptr->version = H5C__CURR_AUTO_SIZE_CTL_VER; diff --git a/src/H5Aint.c b/src/H5Aint.c index d63b5f0..a89c1c9 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -150,32 +150,21 @@ H5A_compact_build_table_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, /* Re-allocate the table if necessary */ if(udata->curr_attr == udata->atable->nattrs) { - size_t i; - size_t n = MAX(1, 2 * udata->atable->nattrs); - H5A_t **table = (H5A_t **)H5FL_SEQ_CALLOC(H5A_t_ptr, n); - - /* Use attribute functions for operation */ - for(i=0; iatable->nattrs; i++) { - table[i] = (H5A_t *)H5FL_CALLOC(H5A_t); - if(NULL == H5A_copy(table[i], udata->atable->attrs[i])) - HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") - if(H5A_close(udata->atable->attrs[i]) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, H5_ITER_ERROR, "can't close attribute") - } - - if(udata->atable->nattrs) - udata->atable->attrs = (H5A_t **)H5FL_SEQ_FREE(H5A_t_ptr, udata->atable->attrs); + H5A_t **new_table; /* New table for attributes */ + size_t new_table_size; /* Number of attributes in new table */ - if(!table) + /* Allocate larger table */ + new_table_size = MAX(1, 2 * udata->atable->nattrs); + if(NULL == (new_table = (H5A_t **)H5FL_SEQ_REALLOC(H5A_t_ptr, udata->atable->attrs, new_table_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "unable to extend attribute table") - udata->atable->attrs = table; - udata->atable->nattrs = n; + + /* Update table information in user data */ + udata->atable->attrs = new_table; + udata->atable->nattrs = new_table_size; } /* end if */ /* Copy attribute into table */ - udata->atable->attrs[udata->curr_attr] = (H5A_t *)H5FL_CALLOC(H5A_t); - - if(NULL == H5A_copy(udata->atable->attrs[udata->curr_attr], (const H5A_t *)mesg->native)) + if(NULL == (udata->atable->attrs[udata->curr_attr] = H5A_copy(NULL, (const H5A_t *)mesg->native))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") /* Assign [somewhat arbitrary] creation order value, if requested */ diff --git a/src/H5B.c b/src/H5B.c index 326d675..d915b01 100644 --- a/src/H5B.c +++ b/src/H5B.c @@ -1760,7 +1760,7 @@ done: H5B_shared_t * H5B_shared_new(const H5F_t *f, const H5B_class_t *type, size_t sizeof_rkey) { - H5B_shared_t *shared; /* New shared B-tree struct */ + H5B_shared_t *shared = NULL; /* New shared B-tree struct */ size_t u; /* Local index variable */ H5B_shared_t *ret_value; /* Return value */ @@ -1772,8 +1772,8 @@ H5B_shared_new(const H5F_t *f, const H5B_class_t *type, size_t sizeof_rkey) HDassert(type); /* Allocate space for the shared structure */ - if(NULL == (shared = H5FL_MALLOC(H5B_shared_t))) - HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "memory allocation failed for shared B-tree info") + if(NULL == (shared = H5FL_CALLOC(H5B_shared_t))) + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for shared B-tree info") /* Set up the "global" information for this file's groups */ shared->type = type; @@ -1788,12 +1788,12 @@ H5B_shared_new(const H5F_t *f, const H5B_class_t *type, size_t sizeof_rkey) /* Allocate shared buffers */ if(NULL == (shared->page = H5FL_BLK_MALLOC(page, shared->sizeof_rnode))) - HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree page") + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for B-tree page") #ifdef H5_CLEAR_MEMORY HDmemset(shared->page, 0, shared->sizeof_rnode); #endif /* H5_CLEAR_MEMORY */ if(NULL == (shared->nkey = H5FL_SEQ_MALLOC(size_t, (size_t)(shared->two_k + 1)))) - HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree page") + HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "memory allocation failed for B-tree native keys") /* Initialize the offsets into the native key buffer */ for(u = 0; u < (shared->two_k + 1); u++) @@ -1803,6 +1803,15 @@ HDmemset(shared->page, 0, shared->sizeof_rnode); ret_value = shared; done: + if(NULL == ret_value) + if(shared) { + if(shared->page) + shared->page = H5FL_BLK_FREE(page, shared->page); + if(shared->nkey) + shared->nkey = H5FL_SEQ_FREE(size_t, shared->nkey); + shared = H5FL_FREE(H5B_shared_t, shared); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5B_shared_new() */ diff --git a/src/H5C.c b/src/H5C.c index 7fc651b..ef58012 100644 --- a/src/H5C.c +++ b/src/H5C.c @@ -9814,12 +9814,8 @@ H5C__autoadjust__ageout__insert_new_marker(H5C_t * cache_ptr) i++; } - HDassert( i < H5C__MAX_EPOCH_MARKERS ); - - if ( (cache_ptr->epoch_marker_active)[i] != FALSE ) { - + if(i >= H5C__MAX_EPOCH_MARKERS) HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Can't find unused marker.") - } HDassert( ((cache_ptr->epoch_markers)[i]).addr == (haddr_t)i ); HDassert( ((cache_ptr->epoch_markers)[i]).next == NULL ); diff --git a/src/H5Dbtree.c b/src/H5Dbtree.c index 141e1f2..e756f3a 100644 --- a/src/H5Dbtree.c +++ b/src/H5Dbtree.c @@ -1485,8 +1485,9 @@ done: /* Free the raw B-tree node buffer */ if(NULL == storage.u.btree.shared) HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "ref-counted page nil") - if(H5RC_DEC(storage.u.btree.shared) < 0) - HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "unable to decrement ref-counted page") + else + if(H5RC_DEC(storage.u.btree.shared) < 0) + HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "unable to decrement ref-counted page") } /* end if */ FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index cb7901e..f90e7fa 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -4396,16 +4396,22 @@ H5D_chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, /* create a memory copy of the variable-length datatype */ if(NULL == (dt_mem = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy") - if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0) + if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0) { + (void)H5T_close(dt_mem); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register memory datatype") + } /* end if */ /* create variable-length datatype at the destinaton file */ if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy") - if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) + if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) { + (void)H5T_close(dt_dst); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk") - if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0) + } /* end if */ + if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0) { + (void)H5T_close(dt_dst); HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register destination file datatype") + } /* end if */ /* Set up the conversion functions */ if(NULL == (tpath_src_mem = H5T_path_find(dt_src, dt_mem, NULL, NULL, dxpl_id, FALSE))) @@ -4435,7 +4441,7 @@ H5D_chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, /* Atomize */ if((sid_buf = H5I_register(H5I_DATASPACE, buf_space, FALSE)) < 0) { - H5S_close(buf_space); + (void)H5S_close(buf_space); HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace ID") } /* end if */ diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 971c514..ad068ad 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -234,6 +234,21 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned UNUSED mesg_fl ret_value = attr; done: + if(NULL == ret_value) { + if(attr) { + if(attr->shared) { + /* Free any dynamicly allocated items */ + if(H5A_free(attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, NULL, "can't release attribute info") + + /* Destroy shared attribute struct */ + attr->shared = H5FL_FREE(H5A_shared_t, attr->shared); + } /* end if */ + } /* end if */ + + attr = H5FL_FREE(H5A_t, attr); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_attr_decode() */ diff --git a/test/btree2.c b/test/btree2.c index fb24433..eabd208 100644 --- a/test/btree2.c +++ b/test/btree2.c @@ -2770,7 +2770,7 @@ test_insert_lots(hid_t fapl, const H5B2_create_t *cparam, curr_time=1109170019; HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); #endif /* QAK */ - HDsrandom((unsigned long)curr_time); + HDsrandom((unsigned)curr_time); /* * Test inserting many records into v2 B-tree @@ -6445,7 +6445,7 @@ test_remove_lots(const char *env_h5_drvr, hid_t fapl, const H5B2_create_t *cpara curr_time = 1163537969; HDfprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); #endif /* QAK */ - HDsrandom((unsigned long)curr_time); + HDsrandom((unsigned)curr_time); /* * Test removing many records into v2 B-tree diff --git a/test/dsets.c b/test/dsets.c index 58fa2c8..b4c6a84 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -7309,7 +7309,7 @@ main(void) envval = "nomatch"; /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); /* Testing setup */ h5_reset(); diff --git a/test/dt_arith.c b/test/dt_arith.c index 43855a8..420570a 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -5218,7 +5218,7 @@ main(void) unsigned long nerrors = 0; /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); reset_hdf5(); diff --git a/test/dtypes.c b/test/dtypes.c index d2db20b..04f526a 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -6337,7 +6337,7 @@ main(void) hid_t fapl = -1; /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); reset_hdf5(); fapl = h5_fileaccess(); diff --git a/test/hyperslab.c b/test/hyperslab.c index 194c0f6..b756449 100644 --- a/test/hyperslab.c +++ b/test/hyperslab.c @@ -1234,7 +1234,7 @@ main(int argc, char *argv[]) printf("\n"); /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); /* * Open the library explicitly for thread-safe builds, so per-thread diff --git a/test/istore.c b/test/istore.c index fff6706..fb0f3fc 100644 --- a/test/istore.c +++ b/test/istore.c @@ -596,7 +596,7 @@ main(int argc, char *argv[]) printf("\n"); /* Set the random # seed */ - HDsrandom((unsigned long)HDtime(NULL)); + HDsrandom((unsigned)HDtime(NULL)); /* Reset library */ h5_reset(); diff --git a/test/ntypes.c b/test/ntypes.c index a82f051..87484d9 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -23,8 +23,8 @@ #include "h5test.h" const char *FILENAME[] = { - "ntypes", - NULL + "ntypes", + NULL }; #define DIM0 100 @@ -60,6 +60,7 @@ int ipoints3[DIM0][DIM1][5], icheck3[DIM0][DIM1][5]; #define SPACE2_DIM1 10 #define SPACE2_DIM2 10 + /*------------------------------------------------------------------------- * Function: test_atomic_dtype @@ -80,11 +81,11 @@ int ipoints3[DIM0][DIM1][5], icheck3[DIM0][DIM1][5]; static herr_t test_atomic_dtype(hid_t file) { - hid_t dataset, space; - hid_t dtype, native_type; - int i, j, n; - hsize_t dims[2]; - void *tmp; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1; + int i, j, n; + hsize_t dims[2]; + void *tmp = NULL; TESTING("atomic datatype"); @@ -101,7 +102,8 @@ test_atomic_dtype(hid_t file) /*------------------- Test data values ------------------------*/ /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_1, H5T_STD_I32BE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Write the data to the dataset */ if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2) < 0) @@ -127,18 +129,20 @@ test_atomic_dtype(hid_t file) TEST_ERROR; /* Read the dataset back. The temporary buffer is for special platforms - * like Cray. */ - tmp = malloc((size_t)(DIM0 * DIM1 * H5Tget_size(native_type))); + * like Cray. */ + if(NULL == (tmp = HDmalloc((size_t)(DIM0 * DIM1 * H5Tget_size(native_type))))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) TEST_ERROR; /* Copy data from temporary buffer to destination buffer */ - memcpy(icheck2, tmp, (size_t)(DIM0 * DIM1 * H5Tget_size(native_type))); - free(tmp); + HDmemcpy(icheck2, tmp, (size_t)(DIM0 * DIM1 * H5Tget_size(native_type))); + HDfree(tmp); + tmp = NULL; /* Convert to the integer type */ - if(H5Tconvert(native_type, H5T_NATIVE_INT, (DIM0*DIM1), icheck2, NULL, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, H5T_NATIVE_INT, (DIM0 * DIM1), icheck2, NULL, H5P_DEFAULT) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -159,7 +163,8 @@ test_atomic_dtype(hid_t file) /* Create the dataset of H5T_STD_I64LE */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_2, H5T_STD_I64LE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR; @@ -181,7 +186,8 @@ test_atomic_dtype(hid_t file) /* Create the dataset of H5T_STD_I8LE */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_3, H5T_STD_I8LE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR; @@ -203,7 +209,8 @@ test_atomic_dtype(hid_t file) /* Create the dataset of H5T_IEEE_F32BE */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_4, H5T_IEEE_F32BE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR; @@ -225,7 +232,8 @@ test_atomic_dtype(hid_t file) /* Create the dataset of H5T_IEEE_F64BE */ if((dataset = H5Dcreate2(file, DSET_ATOMIC_NAME_5, H5T_IEEE_F64BE, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR; @@ -253,6 +261,16 @@ test_atomic_dtype(hid_t file) return 0; error: + if(tmp) + HDfree(tmp); + + H5E_BEGIN_TRY { + H5Dclose(dataset); + H5Tclose(native_type); + H5Tclose(dtype); + H5Sclose(space); + } H5E_END_TRY; + return -1; } @@ -286,14 +304,14 @@ test_compound_dtype2(hid_t file) s2 st; unsigned long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, tid_m, tid_m2, - mem_id, nest_mem_id; - int i, j, n; - hsize_t dims[2]; - s1 *temp_point, *temp_check; - s1 *points=NULL, *check=NULL; - void *tmp, *bkg; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1, + tid_m2 = -1, mem_id = -1, nest_mem_id = -1; + int i, j, n; + hsize_t dims[2]; + s1 *temp_point = NULL, *temp_check = NULL; + s1 *points = NULL, *check = NULL; + void *tmp = NULL, *bkg = NULL; TESTING("nested compound datatype"); @@ -304,15 +322,15 @@ test_compound_dtype2(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for (i = n = 0, temp_point=points; i < DIM0; i++) { - for (j = 0; j < DIM1; j++,temp_point++) { - temp_point->c = 't'; - temp_point->i = n++; - temp_point->st.c2 = (short)(i + j); - temp_point->st.l2 = (i * 5 + j * 50) * n; - temp_point->l = (unsigned long long)((i * 10 + j * 100) * n); - } - } + for(i = n = 0, temp_point = points; i < DIM0; i++) { + for(j = 0; j < DIM1; j++, temp_point++) { + temp_point->c = 't'; + temp_point->i = n++; + temp_point->st.c2 = (short)(i + j); + temp_point->st.l2 = (i * 5 + j * 50) * n; + temp_point->l = (unsigned long long)((i * 10 + j * 100) * n); + } /* end for */ + } /* end for */ /* Create the data space */ dims[0] = DIM0; @@ -353,7 +371,8 @@ test_compound_dtype2(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_2, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create compound datatype for memory */ if((tid_m2 = H5Tcreate(H5T_COMPOUND, sizeof(s2))) < 0) TEST_ERROR; @@ -369,7 +388,7 @@ test_compound_dtype2(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -451,36 +470,39 @@ test_compound_dtype2(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = malloc(DIM0*DIM1*H5Tget_size(native_type)); - if((bkg=calloc(sizeof(s1),DIM0*DIM1))==NULL) + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR + if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1))) TEST_ERROR; if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); - free(tmp); + HDmemcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0) TEST_ERROR; - free(bkg); + HDfree(bkg); + bkg = NULL; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++, temp_point++,temp_check++) { - if(temp_point->c != temp_check->c || - temp_point->i != temp_check->i || - temp_point->st.c2 != temp_check->st.c2 || - temp_point->st.l2 != temp_check->st.l2 || - temp_point->l != temp_check->l ) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); - goto error; - } - } - } + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) { + for(j = 0; j < DIM1; j++, temp_point++, temp_check++) { + if(temp_point->c != temp_check->c || + temp_point->i != temp_check->i || + temp_point->st.c2 != temp_check->st.c2 || + temp_point->st.l2 != temp_check->st.l2 || + temp_point->l != temp_check->l ) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } /* end if */ + } /* end for */ + } /* end for */ /* Close temporary datatypes */ if(H5Tclose(tid2) < 0) TEST_ERROR; @@ -494,17 +516,35 @@ test_compound_dtype2(hid_t file) H5Tclose(tid_m); /* Free memory for test data */ - free(points); - free(check); + HDfree(points); + HDfree(check); PASSED(); return 0; error: - if(points!=NULL) - free(points); - if(check!=NULL) - free(check); + if(tmp) + HDfree(tmp); + if(bkg) + HDfree(bkg); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid_m); + H5Tclose(tid_m2); + H5Sclose(space); + H5Tclose(mem_id); + H5Tclose(nest_mem_id); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + } H5E_END_TRY; + return -1; } @@ -533,17 +573,19 @@ test_compound_dtype(hid_t file) unsigned int i; long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, mem_id; - int i, j, n; - hsize_t dims[2]; - s1 *temp_point, *temp_check; - s1 *points, *check; - void *tmp, *bkg; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, mem_id = -1; + int i, j, n; + hsize_t dims[2]; + s1 *temp_point = NULL; + s1 *temp_check = NULL; + s1 *points = NULL; + s1 *check = NULL; + void *tmp = NULL; + void *bkg = NULL; TESTING("compound datatype"); - /* Allocate space for the points & check arrays */ if(NULL == (points = (s1 *)HDmalloc(sizeof(s1) * DIM0 * DIM1))) TEST_ERROR; @@ -551,12 +593,12 @@ test_compound_dtype(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for(i = n = 0, temp_point=points; i < DIM0; i++) - for(j = 0; j < DIM1; j++,temp_point++) { - temp_point->c = 't'; - temp_point->i = (unsigned int)(n++); - temp_point->l = (i*10+j*100)*n; - } /* end for */ + for(i = n = 0, temp_point = points; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++) { + temp_point->c = 't'; + temp_point->i = (unsigned int)(n++); + temp_point->l = (i * 10 + j * 100) * n; + } /* end for */ /* Create the data space */ dims[0] = DIM0; @@ -573,7 +615,8 @@ test_compound_dtype(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create compound datatype for datatype in memory */ if((tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR; @@ -583,7 +626,7 @@ test_compound_dtype(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -633,33 +676,35 @@ test_compound_dtype(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = malloc(DIM0*DIM1*H5Tget_size(native_type)); - bkg = calloc(sizeof(s1),DIM0*DIM1); + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR + if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); - free(tmp); + HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid2, (DIM0*DIM1), check, bkg, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, tid2, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0) TEST_ERROR; - free(bkg); + HDfree(bkg); + bkg = NULL; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++, temp_point++,temp_check++) { - if(temp_point->c != temp_check->c || - temp_point->i != temp_check->i || - temp_point->l != temp_check->l ) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); - goto error; - } - } - } + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++, temp_check++) + if(temp_point->c != temp_check->c || + temp_point->i != temp_check->i || + temp_point->l != temp_check->l ) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } /* end if */ /* Close datatype */ if(H5Tclose(tid) < 0) TEST_ERROR; @@ -670,13 +715,33 @@ test_compound_dtype(hid_t file) H5Tclose(tid2); /* Free memory for test data */ - free(points); - free(check); + HDfree(points); + HDfree(check); PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + if(bkg) + HDfree(bkg); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Tclose(tid); + H5Sclose(space); + H5Tclose(mem_id); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid2); + } H5E_END_TRY; + return -1; } @@ -705,15 +770,15 @@ test_compound_dtype3(hid_t file) int a[5]; long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, tid_m, tid_m2, - mem_id, nest_mem_id; - hsize_t array_dims[1]={5}; - int i, j, k, n; - hsize_t dims[2]; - s1 *temp_point, *temp_check; - s1 *points=NULL, *check=NULL; - void *tmp, *bkg; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1, + tid_m2 = -1, mem_id = -1, nest_mem_id = -1; + hsize_t array_dims[1] = {5}; + int i, j, k, n; + hsize_t dims[2]; + s1 *temp_point = NULL, *temp_check = NULL; + s1 *points = NULL, *check = NULL; + void *tmp = NULL, *bkg = NULL; TESTING("compound datatype with array as field"); @@ -724,13 +789,13 @@ test_compound_dtype3(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for(i = n = 0, temp_point=points; i < DIM0; i++) - for(j = 0; j < DIM1; j++,temp_point++) { - temp_point->c = 't'; - temp_point->l = (i*10+j*100)*n; - for(k = 0; k < 5; k++) - (temp_point->a)[k] = n++; - } /* end for */ + for(i = n = 0, temp_point = points; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++) { + temp_point->c = 't'; + temp_point->l = (i * 10 + j * 100) * n; + for(k = 0; k < 5; k++) + (temp_point->a)[k] = n++; + } /* end for */ /* Create the data space */ dims[0] = DIM0; @@ -750,7 +815,8 @@ test_compound_dtype3(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_3, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create array datatype */ if((tid_m2 = H5Tarray_create2(H5T_NATIVE_INT, 1, array_dims)) < 0) TEST_ERROR; @@ -763,7 +829,7 @@ test_compound_dtype3(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -825,42 +891,44 @@ test_compound_dtype3(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = malloc(DIM0*DIM1*H5Tget_size(native_type)); - if((bkg=calloc(sizeof(s1),DIM0*DIM1))==NULL) + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR; + if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1))) TEST_ERROR; if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); - free(tmp); + HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0) TEST_ERROR; - free(bkg); + HDfree(bkg); + bkg = NULL; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++, temp_point++,temp_check++) { - if(temp_point->c != temp_check->c || - temp_point->l != temp_check->l ) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); - goto error; - } - - for (k = 0; k < 5; k++) { + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++, temp_check++) { + if(temp_point->c != temp_check->c || + temp_point->l != temp_check->l ) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } /* end if */ + + for(k = 0; k < 5; k++) { if(temp_point->a[k] != temp_check->a[k]) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d,%d\n", i, j, k); - goto error; - } - } - } - } + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d,%d\n", i, j, k); + goto error; + } /* end if */ + } /* end for */ + } /* end for */ H5Dclose(dataset); H5Tclose(dtype); @@ -869,13 +937,36 @@ test_compound_dtype3(hid_t file) H5Tclose(tid_m2); /* Free memory for test data */ - free(points); - free(check); + HDfree(points); + HDfree(check); PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + if(bkg) + HDfree(bkg); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Tclose(mem_id); + H5Tclose(nest_mem_id); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid_m); + H5Tclose(tid_m2); + } H5E_END_TRY; + return -1; } @@ -904,14 +995,14 @@ test_compound_opaque(hid_t file) unsigned char o[5]; long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, tid_m, - mem_id; - int i, j, k, n; - hsize_t dims[2]; - s1 *temp_point, *temp_check; - s1 *points=NULL, *check=NULL; - void *tmp, *bkg; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid_m = -1, + mem_id = -1; + int i, j, k, n; + hsize_t dims[2]; + s1 *temp_point = NULL, *temp_check = NULL; + s1 *points = NULL, *check = NULL; + void *tmp = NULL, *bkg = NULL; TESTING("compound datatype with opaque field"); @@ -922,13 +1013,13 @@ test_compound_opaque(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for(i = n = 0, temp_point=points; i < DIM0; i++) - for(j = 0; j < DIM1; j++,temp_point++) { - temp_point->c = 't'; - temp_point->l = (i*10+j*100)*n; - for(k = 0; k < 5; k++) - (temp_point->o)[k] = (unsigned char)(n++); - } /* end for */ + for(i = n = 0, temp_point = points; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++) { + temp_point->c = 't'; + temp_point->l = (i * 10 + j * 100) * n; + for(k = 0; k < 5; k++) + (temp_point->o)[k] = (unsigned char)(n++); + } /* end for */ /* Create the data space */ dims[0] = DIM0; @@ -949,7 +1040,8 @@ test_compound_opaque(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_4, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create compound datatype for datatype in memory */ if((tid_m = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR; @@ -959,7 +1051,7 @@ test_compound_opaque(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -1014,42 +1106,44 @@ test_compound_opaque(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = HDmalloc(DIM0*DIM1*H5Tget_size(native_type)); - if((bkg=HDcalloc(sizeof(s1),DIM0*DIM1))==NULL) + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR; + if(NULL == (bkg = HDcalloc(sizeof(s1), DIM0 * DIM1))) TEST_ERROR; if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - HDmemcpy(check, tmp, DIM0*DIM1*H5Tget_size(native_type)); + HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, bkg, H5P_DEFAULT)) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, bkg, H5P_DEFAULT) < 0) TEST_ERROR; HDfree(bkg); + bkg = NULL; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++, temp_point++,temp_check++) { - if(temp_point->c != temp_check->c || - temp_point->l != temp_check->l ) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); - goto error; - } - - for (k = 0; k < 5; k++) { + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) + for(j = 0; j < DIM1; j++, temp_point++, temp_check++) { + if(temp_point->c != temp_check->c || + temp_point->l != temp_check->l ) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } /* end if */ + + for(k = 0; k < 5; k++) { if(temp_point->o[k] != temp_check->o[k]) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d,%d\n", i, j, k); - goto error; - } - } - } - } + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d,%d\n", i, j, k); + goto error; + } /* end if */ + } /* end for */ + } /* end for */ H5Dclose(dataset); H5Tclose(dtype); @@ -1063,7 +1157,28 @@ test_compound_opaque(hid_t file) PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + if(bkg) + HDfree(bkg); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Tclose(mem_id); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid_m); + } H5E_END_TRY; + return -1; } @@ -1087,28 +1202,28 @@ test_compound_opaque(hid_t file) static herr_t test_enum_dtype(hid_t file) { - hid_t dataset, space; - hid_t tid, tid_m, dtype, native_type; - int i, j, n; - hsize_t dims[2]; - void *tmp; - short colors[8]; - unsigned char sub_colors[16]; - const char *mname[] = { "RED", - "GREEN", - "BLUE", - "YELLOW", - "PINK", - "PURPLE", - "ORANGE", - "WHITE" }; + hid_t dataset = -1, space = -1; + hid_t tid = -1, tid_m = -1, dtype = -1, native_type = -1; + int i, j, n; + hsize_t dims[2]; + void *tmp = NULL; + short colors[8]; + unsigned char sub_colors[16]; + const char *mname[] = { "RED", + "GREEN", + "BLUE", + "YELLOW", + "PINK", + "PURPLE", + "ORANGE", + "WHITE" }; TESTING("enum datatype"); /* Initialize the dataset */ for(i = 0; i < DIM0; i++) for(j = 0, n = 0; j < DIM1; j++, n++) - spoints2[i][j] = (short)((i * 10 + j * 100 + n) % 8); + spoints2[i][j] = (short)((i * 10 + j * 100 + n) % 8); /* Create the data space */ dims[0] = DIM0; @@ -1126,7 +1241,8 @@ test_enum_dtype(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_ENUM_NAME, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Construct enum type based on native type in memory */ if((tid_m = H5Tenum_create(H5T_NATIVE_SHORT)) < 0) TEST_ERROR; @@ -1138,7 +1254,7 @@ test_enum_dtype(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, spoints2) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -1159,30 +1275,30 @@ test_enum_dtype(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = malloc(DIM0 * DIM1 * H5Tget_size(native_type)); + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(scheck2, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); - free(tmp); + HDmemcpy(scheck2, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), scheck2, NULL, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), scheck2, NULL, H5P_DEFAULT) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ - for (i = 0; i < DIM0; i++) { - for (j = 0; j < DIM1; j++) { - if(spoints2[i][j] != scheck2[i][j]) { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %d,%d\n", i, j); + for(i = 0; i < DIM0; i++) + for(j = 0; j < DIM1; j++) + if(spoints2[i][j] != scheck2[i][j]) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); printf(" spoints2[i][j]=%hd, scheck2[i][j]=%hd\n", spoints2[i][j], scheck2[i][j]); - goto error; - } - } - } + goto error; + } /* end if */ H5Dclose(dataset); H5Tclose(dtype); @@ -1191,7 +1307,20 @@ test_enum_dtype(hid_t file) PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid_m); + } H5E_END_TRY; + return -1; } @@ -1220,13 +1349,13 @@ test_array_dtype(hid_t file) int i; long long l; } s1; - hid_t dataset, space; - hid_t dtype, native_type, tid, tid2, tid3, tid_m; - int i, j, k, n; - hsize_t space_dims[2], array_dims[1]={5}; - s1 *temp_point, *temp_check; - s1 *points=NULL, *check=NULL; - void *tmp; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid2 = -1, tid3 = -1, tid_m = -1; + int i, j, k, n; + hsize_t space_dims[2], array_dims[1]={5}; + s1 *temp_point = NULL, *temp_check = NULL; + s1 *points = NULL, *check = NULL; + void *tmp = NULL; TESTING("array of compound datatype"); @@ -1237,13 +1366,13 @@ test_array_dtype(hid_t file) TEST_ERROR; /* Initialize the dataset */ - for(i = n = 0, temp_point=points; i < DIM0; i++) - for(j = 0; j < DIM1; j++) + for(i = n = 0, temp_point = points; i < DIM0; i++) + for(j = 0; j < DIM1; j++) for(k = 0; k < 5; k++,temp_point++) { temp_point->c= 't'; temp_point->i= n++; - temp_point->l= (i*10+j*100)*n; - } + temp_point->l= (i * 10 + j * 100) * n; + } /* end for */ /* Create the data space */ space_dims[0] = DIM0; @@ -1263,7 +1392,8 @@ test_array_dtype(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_ARRAY_NAME, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create compound datatype for datatype in memory */ if((tid3 = H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR; @@ -1276,7 +1406,7 @@ test_array_dtype(hid_t file) /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -1298,32 +1428,31 @@ test_array_dtype(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)); + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); - free(tmp); + HDmemcpy(check, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), check, NULL, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), check, NULL, H5P_DEFAULT) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ - for (i = 0, temp_point=points, temp_check=check; i < DIM0; i++) { - for (j = 0; j < DIM1; j++) { - for (k = 0; k < 5; k++, temp_point++,temp_check++) { + for(i = 0, temp_point = points, temp_check = check; i < DIM0; i++) + for(j = 0; j < DIM1; j++) + for(k = 0; k < 5; k++, temp_point++, temp_check++) if(temp_point->c != temp_check->c || - temp_point->i != temp_check->i || - temp_point->l != temp_check->l ) { + temp_point->i != temp_check->i || + temp_point->l != temp_check->l ) { H5_FAILED(); printf(" Read different values than written.\n"); printf(" At index %d,%d\n", i, j); goto error; - } - } - } - } + } /* end if */ /* Close HDF5 objects */ if(H5Dclose(dataset)) TEST_ERROR; @@ -1333,17 +1462,32 @@ test_array_dtype(hid_t file) if(H5Tclose(tid3) < 0) TEST_ERROR; /* Free memory for test data */ - free(points); - free(check); + HDfree(points); + HDfree(check); PASSED(); return 0; error: - if(points!=NULL) - free(points); - if(check!=NULL) - free(check); + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + if(points) + HDfree(points); + if(check) + HDfree(check); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid3); + H5Tclose(tid_m); + } H5E_END_TRY; + return -1; } @@ -1367,17 +1511,17 @@ error: static herr_t test_array_dtype2(hid_t file) { - hid_t dataset, space; - hid_t dtype, native_type, tid, tid_m; - int i, j, k, n; - hsize_t space_dims[2], array_dims[1]={5}; - void *tmp; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, tid = -1, tid_m = -1; + int i, j, k, n; + hsize_t space_dims[2], array_dims[1] = {5}; + void *tmp = NULL; TESTING("array of atomic datatype"); /* Initialize the dataset */ for(i = n = 0;i < DIM0; i++) - for(j = 0; j < DIM1; j++) + for(j = 0; j < DIM1; j++) for(k = 0; k < 5; k++) ipoints3[i][j][k] = n++; @@ -1391,14 +1535,15 @@ test_array_dtype2(hid_t file) /* Create the dataset */ if((dataset = H5Dcreate2(file, DSET_ARRAY2_NAME, tid, space, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Create array datatype for memory */ if((tid_m = H5Tarray_create2(H5T_NATIVE_INT, 1, array_dims)) < 0) TEST_ERROR; /* Write the data to the dataset */ if(H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints3) < 0) - TEST_ERROR; + TEST_ERROR; /* Close dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; @@ -1409,7 +1554,6 @@ test_array_dtype2(hid_t file) /* Close dataspace */ if(H5Sclose(space) < 0) TEST_ERROR; - /* Open dataset again to check H5Tget_native_type */ if((dataset = H5Dopen2(file, DSET_ARRAY2_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -1420,30 +1564,29 @@ test_array_dtype2(hid_t file) /* Read the dataset back. Temporary buffer is for special platforms like * Cray */ - tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)); + if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type)))) + TEST_ERROR if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp) < 0) - TEST_ERROR; + TEST_ERROR; - memcpy(icheck3, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); - free(tmp); + HDmemcpy(icheck3, tmp, DIM0 * DIM1 * H5Tget_size(native_type)); + HDfree(tmp); + tmp = NULL; - if(H5Tconvert(native_type, tid_m, (DIM0*DIM1), icheck3, NULL, H5P_DEFAULT) < 0) + if(H5Tconvert(native_type, tid_m, (DIM0 * DIM1), icheck3, NULL, H5P_DEFAULT) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ - for (i = 0; i < DIM0; i++) { - for (j = 0; j < DIM1; j++) { - for (k = 0; k < 5; k++) { + for(i = 0; i < DIM0; i++) + for(j = 0; j < DIM1; j++) + for(k = 0; k < 5; k++) if(icheck3[i][j][k] != ipoints3[i][j][k]) { H5_FAILED(); printf(" Read different values than written.\n"); printf(" At index %d,%d\n", i, j); goto error; - } - } - } - } + } /* end if */ /* Close HDF5 objects */ if(H5Dclose(dataset)) TEST_ERROR; @@ -1455,6 +1598,19 @@ test_array_dtype2(hid_t file) return 0; error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(tid); + H5Tclose(tid_m); + } H5E_END_TRY; + return -1; } @@ -1478,37 +1634,36 @@ error: static herr_t test_vl_dtype(hid_t file) { - hvl_t wdata[SPACE1_DIM1]; /* Information to write */ - hvl_t rdata[SPACE1_DIM1]; /* Information read in */ - hvl_t *t1, *t2; /* Temporary pointer to VL information */ - hsize_t dims1[] = {SPACE1_DIM1}; - hid_t dataset, space; - hid_t dtype, native_type, nat_super_type, tid, tid2, tid_m, tid_m2; - size_t i, j, k; - void* *tmp; + hvl_t wdata[SPACE1_DIM1]; /* Information to write */ + hvl_t rdata[SPACE1_DIM1]; /* Information read in */ + hvl_t *t1, *t2; /* Temporary pointer to VL information */ + hsize_t dims1[] = {SPACE1_DIM1}; + hid_t dataset = -1, space = -1; + hid_t dtype = -1, native_type = -1, nat_super_type = -1, tid = -1, tid2 = -1, tid_m = -1, tid_m2 = -1; + size_t i, j, k; + void **tmp = NULL; TESTING("variable length datatype"); /* Allocate and initialize VL data to write */ - for(i=0; ip = HDmalloc((j + 1) * sizeof(unsigned int)); - if(t1->p==NULL) { + if(NULL == t1->p) { H5_FAILED(); printf(" Cannot allocate memory for VL data! i=%u, j=%u\n",(unsigned)i,(unsigned)j); goto error; } /* end if */ - t1->len=j+1; - for(k=0; k<(j+1); k++) { - ((unsigned int *)t1->p)[k]=(unsigned int)(i*100+j*10+k); - } + t1->len = j + 1; + for(k = 0; k < (j + 1); k++) + ((unsigned int *)t1->p)[k] = (unsigned int)(i * 100 + j * 10 + k); } /* end for */ } /* end for */ @@ -1566,7 +1721,7 @@ test_vl_dtype(hid_t file) printf(" VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len); goto error; } /* end if */ - for(t1 = (hvl_t *)wdata[i].p, t2 = (hvl_t *)rdata[i].p, j = 0; jlen != t2->len) { H5_FAILED(); printf(" VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len); @@ -1575,36 +1730,38 @@ test_vl_dtype(hid_t file) /* use temporary buffer to convert datatype. This is for special * platforms like Cray */ - tmp = (void **)HDmalloc(t2->len * sizeof(unsigned int)); + if(NULL == (tmp = (void **)HDmalloc(t2->len * sizeof(unsigned int)))) + TEST_ERROR HDmemcpy(tmp, t2->p, t2->len * H5Tget_size(nat_super_type)); - if(H5Tconvert(nat_super_type, H5T_NATIVE_UINT, t2->len, tmp, NULL, H5P_DEFAULT)) + if(H5Tconvert(nat_super_type, H5T_NATIVE_UINT, t2->len, tmp, NULL, H5P_DEFAULT) < 0) TEST_ERROR; - for(k=0; klen; k++) { - if( ((unsigned int *)t1->p)[k] != ((unsigned int *)tmp)[k] ) { + for(k = 0; k < t2->len; k++) { + if(((unsigned int *)t1->p)[k] != ((unsigned int *)tmp)[k]) { H5_FAILED(); printf(" VL data don't match!, wdata[%u].p=%d, rdata[%u].p=%u\n", - (unsigned)i,((unsigned int*)t1->p)[k],(unsigned)i,((unsigned int*)tmp)[k]); + (unsigned)i, ((unsigned int*)t1->p)[k], (unsigned)i, ((unsigned int*)tmp)[k]); goto error; - } + } /* end if */ } /* end for */ - free(tmp); + HDfree(tmp); } /* end for */ } /* end for */ /* Reclaim the read VL data */ - if(H5Dvlen_reclaim(native_type,space,H5P_DEFAULT,rdata) < 0) TEST_ERROR; + if(H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, rdata) < 0) TEST_ERROR; /* Reclaim the write VL data */ - if(H5Dvlen_reclaim(native_type,space,H5P_DEFAULT,wdata) < 0) TEST_ERROR; + if(H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, wdata) < 0) TEST_ERROR; /* Close Dataset */ if(H5Dclose(dataset) < 0) TEST_ERROR; /* Close datatype */ if(H5Tclose(native_type) < 0) TEST_ERROR; + native_type = -1; /* reset so that error handling can check for VL reclaim */ if(H5Tclose(dtype) < 0) TEST_ERROR; if(H5Tclose(tid_m) < 0) TEST_ERROR; if(H5Tclose(tid_m2) < 0) TEST_ERROR; @@ -1616,7 +1773,27 @@ test_vl_dtype(hid_t file) PASSED(); return 0; - error: +error: + /* Free memory for test data */ + if(tmp) + HDfree(tmp); + + H5E_BEGIN_TRY { + if(native_type > 0) { + H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, rdata); + H5Dvlen_reclaim(native_type, space, H5P_DEFAULT, wdata); + } /* end if */ + H5Sclose(space); + H5Dclose(dataset); + H5Tclose(dtype); + H5Tclose(native_type); + H5Tclose(nat_super_type); + H5Tclose(tid); + H5Tclose(tid2); + H5Tclose(tid_m); + H5Tclose(tid_m2); + } H5E_END_TRY; + return -1; } /* end test_vl_type() */ @@ -1641,17 +1818,18 @@ static herr_t test_vlstr_dtype(hid_t file) { const char *wdata[SPACE1_DIM1]= { - "Four score and seven years ago our forefathers brought forth on this continent a new nation,", - "conceived in liberty and dedicated to the proposition that all men are created equal.", - "Now we are engaged in a great civil war,", - "testing whether that nation or any nation so conceived and so dedicated can long endure." - }; /* Information to write */ - char *rdata[SPACE1_DIM1]; /* Information read in */ - hid_t dataset; /* Dataset ID */ - hid_t sid1; /* Dataspace ID */ - hid_t tid1,dtype,native_type; /* Datatype ID */ - hsize_t dims1[] = {SPACE1_DIM1}; - unsigned i; /* counting variable */ + "Four score and seven years ago our forefathers brought forth on this continent a new nation,", + "conceived in liberty and dedicated to the proposition that all men are created equal.", + "Now we are engaged in a great civil war,", + "testing whether that nation or any nation so conceived and so dedicated can long endure." + }; /* Information to write */ + char *rdata[SPACE1_DIM1]; /* Information read in */ + hbool_t rdata_alloc = FALSE; /* Whether the read data is allocated */ + hid_t dataset = -1; /* Dataset ID */ + hid_t sid1 = -1; /* Dataspace ID */ + hid_t tid1 = -1, dtype = -1, native_type = -1; /* Datatype ID */ + hsize_t dims1[] = {SPACE1_DIM1}; + unsigned i; /* counting variable */ /* Output message about test being performed */ TESTING("variable length string datatype"); @@ -1691,19 +1869,20 @@ test_vlstr_dtype(hid_t file) /* Read dataset from disk */ if(H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata) < 0) TEST_ERROR; + rdata_alloc = TRUE; /* Compare data read in */ for(i = 0; i < SPACE1_DIM1; i++) { if(HDstrlen(wdata[i]) != HDstrlen(rdata[i])) { H5_FAILED(); printf(" VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n", - (int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i])); + (int)i, (int)HDstrlen(wdata[i]), (int)i, (int)HDstrlen(rdata[i])); goto error; } /* end if */ if(HDstrcmp(wdata[i], rdata[i]) != 0 ) { H5_FAILED(); printf(" VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n", - (int)i,wdata[i],(int)i,rdata[i]); + (int)i, wdata[i], (int)i, rdata[i]); goto error; } /* end if */ } /* end for */ @@ -1719,14 +1898,28 @@ test_vlstr_dtype(hid_t file) if(H5Sclose(sid1) < 0) TEST_ERROR; /* Free memory for rdata */ - for(i=0; i= 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 c67eb0a..473090f 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -112,6 +112,7 @@ h5repack_init(pack_opt_t *options, int verbose, H5F_file_space_type_t strategy, return (options_table_init(&(options->op_tbl))); } + /*------------------------------------------------------------------------- * Function: h5repack_end * @@ -125,6 +126,7 @@ int h5repack_end (pack_opt_t *options) return options_table_free(options->op_tbl); } + /*------------------------------------------------------------------------- * Function: h5repack_addfilter * @@ -135,7 +137,6 @@ int h5repack_end (pack_opt_t *options) * *------------------------------------------------------------------------- */ - int h5repack_addfilter(const char* str, pack_opt_t *options) { @@ -147,38 +148,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; isize; 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 3dcde22..3283ddd 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -4056,6 +4056,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); @@ -4111,24 +4112,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; } /*------------------------------------------------------------------------- -- cgit v0.12