[svn-r13063] Cleaned up some memory issues when copying, in preparation for checking in

code to copy shared messages.  Should be fewer memory leaks and fewer
"uninitialized memory reads."

Tested on kagiso, smirom, and Windows.
This commit is contained in:
James Laird 2006-12-14 13:46:51 -05:00
parent 481cfbe0e9
commit 57a786d9c0
5 changed files with 15 additions and 27 deletions

View File

@ -182,6 +182,10 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
HDassert(layout_dst && H5D_COMPACT == layout_dst->type);
HDassert(dt_src);
/* Create datatype ID for src datatype, so it gets freed */
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* If there's a VLEN source datatype, do type conversion information */
if(H5T_detect_class(dt_src, H5T_VLEN) > 0) {
H5T_path_t *tpath_src_mem, *tpath_mem_dst; /* Datatype conversion paths */
@ -195,10 +199,6 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
size_t max_dt_size; /* Max atatype size */
hsize_t buf_dim; /* Dimension for buffer */
/* Create datatype ID for src datatype */
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* 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")
@ -279,10 +279,6 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
HGOTO_ERROR(H5E_DATASET, H5E_BADITER, FAIL, "unable to reclaim variable-length data")
} /* end if */
else if(H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) {
/* Create datatype ID for src datatype, so it gets freed */
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
if(f_src != f_dst) {
/* Check for expanding references */
if(cpy_info->expand_ref) {

View File

@ -1046,12 +1046,14 @@ H5D_contig_copy(H5F_t *f_src, const H5O_layout_t *layout_src, H5F_t *f_dst,
H5_CHECK_OVERFLOW(total_src_nbytes, hsize_t, size_t);
buf_size = MIN(H5D_TEMP_BUF_SIZE, (size_t)total_src_nbytes);
/* Create datatype ID for src datatype. We may or may not use this ID,
* but this ensures that the src datatype will be freed.
*/
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* If there's a VLEN source datatype, set up type conversion information */
if(H5T_detect_class(dt_src, H5T_VLEN) > 0) {
/* Create datatype ID for src datatype */
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* 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")
@ -1113,10 +1115,6 @@ H5D_contig_copy(H5F_t *f_src, const H5O_layout_t *layout_src, H5F_t *f_dst,
else {
/* Check for reference datatype */
if(H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) {
/* Create datatype ID for src datatype, so it gets freed */
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* Need to fix values of references when copying across files */
if(f_src != f_dst)
fix_ref = TRUE;

View File

@ -3579,6 +3579,10 @@ H5D_istore_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
HDassert(layout_dst && H5D_CHUNKED == layout_dst->type);
HDassert(dt_src);
/* Create datatype ID for src datatype */
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* Create shared B-tree info for each file */
if(H5D_istore_shared_create(f_src, layout_src) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "can't create wrapper for shared B-tree info")
@ -3602,10 +3606,6 @@ H5D_istore_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
hsize_t buf_dim; /* Dimension for buffer */
unsigned u;
/* Create datatype ID for src datatype */
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* 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")
@ -3664,12 +3664,7 @@ H5D_istore_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
do_convert = TRUE;
} /* end if */
else {
/* Create datatype ID for source datatype, so it gets freed */
if(H5T_get_class(dt_src, FALSE) == H5T_REFERENCE) {
/* Create datatype ID for src datatype */
if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* Indicate that type conversion should be performed */
do_convert = TRUE;
} /* end if */

View File

@ -391,7 +391,6 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */,
for(mesgno = 0; mesgno < oh_src->nmesgs; mesgno++) {
/* Set up convenience variables */
mesg_src = &(oh_src->mesg[mesgno]);
mesg_dst = &(oh_dst->mesg[mesgno]);
/* Sanity check */
HDassert(!mesg_src->dirty); /* Should be cleared by earlier call to flush messages */

View File

@ -1376,7 +1376,7 @@ H5T_unlock_cb (void *_dt, hid_t UNUSED id, void UNUSED *key)
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_unlock_cb);
assert (dt);
HDassert (dt && dt->shared);
if (H5T_STATE_IMMUTABLE==dt->shared->state)
dt->shared->state = H5T_STATE_RDONLY;