summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/h5repack_copy.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2011-02-06 03:30:19 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2011-02-06 03:30:19 (GMT)
commit90727b65778c62d80f138496c6bf1a548ace5a23 (patch)
tree3882f921a6c69ade21cccb92310cff7ef9860c28 /tools/h5repack/h5repack_copy.c
parentfceb72c657ee623aa5574208834dc38515170a72 (diff)
downloadhdf5-90727b65778c62d80f138496c6bf1a548ace5a23.zip
hdf5-90727b65778c62d80f138496c6bf1a548ace5a23.tar.gz
hdf5-90727b65778c62d80f138496c6bf1a548ace5a23.tar.bz2
[svn-r20053] Description:
Bring r20052 from trunk to 1.8 branch: Clean up Coverity warnings, and fix some style issues: r19735: Fix for memory leak in test/mf found by valgrind. r19736: Fix memory leak in h5repack. The buffer in copy_objects, when copying the entire dataset at once, was not checked for the presence of a vlen, and vlen storage was never reclaimed. Added check and call to H5D_vlen_reclaim(). r19772: Change H5assert() to if (H5T_VLEN != src->shared->type || H5T_VLEN != dst->shared->type) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a H5T_VLEN datatype") r19774: removed unused priv. r19775: removed unused variables r19778: Fix memory leak comparing for variable length data types. r19834: Fixed memory leaks found by valgrind. Memory errors remain for another day. Tested on: Mac OS X/32 10.6.6 (amazon) w/debug & production (h5committested on branch)
Diffstat (limited to 'tools/h5repack/h5repack_copy.c')
-rw-r--r--tools/h5repack/h5repack_copy.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c
index c8dce9f..3ed045c 100644
--- a/tools/h5repack/h5repack_copy.c
+++ b/tools/h5repack/h5repack_copy.c
@@ -499,23 +499,23 @@ int do_copy_objects(hid_t fidin,
trav_table_t *travt,
pack_opt_t *options) /* repack options */
{
- hid_t grp_in=-1; /* group ID */
- hid_t grp_out=-1; /* group ID */
- hid_t dset_in=-1; /* read dataset ID */
- hid_t dset_out=-1; /* write dataset ID */
- hid_t gcpl_in=-1; /* group creation property list */
- hid_t gcpl_out=-1; /* group creation property list */
- hid_t type_in=-1; /* named type ID */
- hid_t type_out=-1; /* named type ID */
- hid_t dcpl_id=-1; /* dataset creation property list ID */
- hid_t dcpl_out=-1; /* dataset creation property list ID */
- hid_t f_space_id=-1; /* file space ID */
- hid_t ftype_id=-1; /* file type ID */
- hid_t wtype_id=-1; /* read/write type ID */
- named_dt_t *named_dt_head=NULL; /* Pointer to the stack of named datatypes copied */
+ hid_t grp_in = -1; /* group ID */
+ hid_t grp_out = -1; /* group ID */
+ hid_t dset_in = -1; /* read dataset ID */
+ hid_t dset_out = -1; /* write dataset ID */
+ hid_t gcpl_in = -1; /* group creation property list */
+ hid_t gcpl_out = -1; /* group creation property list */
+ hid_t type_in = -1; /* named type ID */
+ hid_t type_out = -1; /* named type ID */
+ hid_t dcpl_id = -1; /* dataset creation property list ID */
+ hid_t dcpl_out = -1; /* dataset creation property list ID */
+ hid_t f_space_id = -1; /* file space ID */
+ hid_t ftype_id = -1; /* file type ID */
+ hid_t wtype_id = -1; /* read/write type ID */
+ named_dt_t *named_dt_head = NULL; /* Pointer to the stack of named datatypes copied */
size_t msize; /* size of type */
hsize_t nelmts; /* number of elements in dataset */
- H5D_space_status_t *space_status; /* determines whether space has been allocated for the dataset */
+ H5D_space_status_t space_status; /* determines whether space has been allocated for the dataset */
int rank; /* rank of dataset */
hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
hsize_t dsize_in; /* input dataset size before filter */
@@ -704,14 +704,12 @@ int do_copy_objects(hid_t fidin,
if(H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0)
goto error;
- if(H5Dget_space_status(dset_in, &space_status) <0)
+ if(H5Dget_space_status(dset_in, &space_status) < 0)
goto error;
nelmts = 1;
- for ( j = 0; j < rank; j++)
- {
+ for(j = 0; j < rank; j++)
nelmts *= dims[j];
- }
/* wtype_id will have already been set if using a named dtype */
if(!is_named) {
@@ -795,20 +793,25 @@ int do_copy_objects(hid_t fidin,
* read/write
*-------------------------------------------------------------------------
*/
- if (nelmts>0 && space_status!=H5D_SPACE_STATUS_NOT_ALLOCATED)
+ if(nelmts > 0 && space_status != H5D_SPACE_STATUS_NOT_ALLOCATED)
{
- size_t need = (size_t)(nelmts*msize); /* bytes needed */
+ size_t need = (size_t)(nelmts * msize); /* bytes needed */
/* have to read the whole dataset if there is only one element in the dataset */
- if ( need < H5TOOLS_MALLOCSIZE )
+ if(need < H5TOOLS_MALLOCSIZE)
buf = HDmalloc(need);
- if (buf != NULL )
- {
- if (H5Dread(dset_in,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0)
+ if(buf != NULL) {
+ if(H5Dread(dset_in, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
goto error;
- if (H5Dwrite(dset_out,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0)
+ if(H5Dwrite(dset_out, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
goto error;
+
+ /* Check if we have VL data in the dataset's
+ * datatype that must be reclaimed */
+ if(TRUE == H5Tdetect_class(wtype_id, H5T_VLEN))
+ if(H5Dvlen_reclaim(wtype_id, f_space_id, H5P_DEFAULT, buf) < 0)
+ goto error;
}
else /* possibly not enough memory, read/write by hyperslabs */
{
@@ -1326,7 +1329,7 @@ copy_user_block(const char *infile, const char *outfile, hsize_t size)
} /* end while */
/* Update size of userblock left to transfer */
- size -= nread;
+ size = size - (hsize_t)nread;
} /* end while */
done: