diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2011-02-08 21:40:24 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2011-02-08 21:40:24 (GMT) |
commit | 84ef7b0ad231923273dd5a1d9612e5d5f271968c (patch) | |
tree | db7b3b37855c1ab9901fac063f84279393cb0dc8 /src/H5Oattribute.c | |
parent | 20b58606caaff62d70a7bdfc03dcead16e1e30d4 (diff) | |
download | hdf5-84ef7b0ad231923273dd5a1d9612e5d5f271968c.zip hdf5-84ef7b0ad231923273dd5a1d9612e5d5f271968c.tar.gz hdf5-84ef7b0ad231923273dd5a1d9612e5d5f271968c.tar.bz2 |
[svn-r20066] Description:
Bring r20065 from trunk to 1.8 branch:
Bring changes from Coverity branch to trunk:
r19975:
Fixed potential mem leak at H5O_attr_open_by_name
r19980:
Fix coverity issue 792.
Free tmp_env_prefix in H5Lexternal.c line 365 if it is not NULL but its contents are 0 when it goes out of scope.
r20039:
Eliminate warnings about nested extern and implicit declarations of parallel_print and address Coverity defects 712-781 by #including h5tools_utils.h in h5diff_array.c, h5diff_attr.c, h5diff_dset.c and h5diff_util.c.
r20046:
Purpose: Address TOCTOU warnings in h5jam and h5unjam
Description: Coverity is afraid that the state of the input file could change
between the call to stat() and the call to open(). This is called a time-of-
check time-of-use (TOCTOU) vulnerability. Modified stat calls to fstat which
uses an open file pointer so it (hopefully) won't complain any more.
r20047:
Addressed coverity issues 135-137, 462-464. Local pointers that needed to be freed in case of error were moved out of a switch statement in src/H5Tnative.c, set to NULL, and checked before freeing.
Tested on:
Mac OS X/32 10.6.6 (amazon) w/debug & production
(h5committested on Coverity branch)
Diffstat (limited to 'src/H5Oattribute.c')
-rw-r--r-- | src/H5Oattribute.c | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index a64b6af..8bb3670 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -472,9 +472,10 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) { H5O_t *oh = NULL; /* Pointer to actual object header */ H5O_ainfo_t ainfo; /* Attribute information for object */ - H5A_t *ret_value; /* Return value */ - H5A_t *exist_attr = NULL; /* Opened attribute object */ + H5A_t *exist_attr = NULL; /* Existing opened attribute object */ + H5A_t *opened_attr = NULL; /* Newly opened attribute object */ htri_t found_open_attr = FALSE; /* Whether opened object is found */ + H5A_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_open_by_name) @@ -500,14 +501,14 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, name)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "failed in finding opened attribute") else if(found_open_attr == TRUE) { - if(NULL == (ret_value = H5A_copy(NULL, exist_attr))) + if(NULL == (opened_attr = H5A_copy(NULL, exist_attr))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute") } /* end else if */ else { /* Check for attributes in dense storage */ if(H5F_addr_defined(ainfo.fheap_addr)) { /* Open attribute with dense storage */ - if(NULL == (ret_value = H5A_dense_open(loc->file, dxpl_id, &ainfo, name))) + if(NULL == (opened_attr = H5A_dense_open(loc->file, dxpl_id, &ainfo, name))) HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "can't open attribute") } /* end if */ else { @@ -530,19 +531,26 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id) /* Get attribute opened from object header */ HDassert(udata.attr); - ret_value = udata.attr; + opened_attr = udata.attr; } /* end else */ /* Mark datatype as being on disk now */ - if(H5T_set_loc(ret_value->shared->dt, loc->file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(opened_attr->shared->dt, loc->file, H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "invalid datatype location") - } /* end else */ + /* Set return value */ + ret_value = opened_attr; + done: if(oh && H5O_unprotect(loc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTUNPROTECT, NULL, "unable to release object header") + /* Release any resources, on error */ + if(NULL == ret_value && opened_attr) + if(H5A_close(opened_attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_attr_open_by_name() */ @@ -606,9 +614,10 @@ H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type, { H5O_t *oh = NULL; /* Object header */ H5A_attr_iter_op_t attr_op; /* Attribute operator */ - H5A_t *exist_attr = NULL; /* Opened attribute object */ + H5A_t *exist_attr = NULL; /* Existing opened attribute object */ + H5A_t *opened_attr = NULL; /* Newly opened attribute object */ htri_t found_open_attr = FALSE; /* Whether opened object is found */ - H5A_t *ret_value = NULL; /* Return value */ + H5A_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_open_by_idx) @@ -620,7 +629,7 @@ H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type, attr_op.u.lib_op = H5O_attr_open_by_idx_cb; /* Iterate over attributes to locate correct one */ - if(H5O_attr_iterate_real((hid_t)-1, loc, dxpl_id, idx_type, order, n, NULL, &attr_op, &ret_value) < 0) + if(H5O_attr_iterate_real((hid_t)-1, loc, dxpl_id, idx_type, order, n, NULL, &attr_op, &opened_attr) < 0) HGOTO_ERROR(H5E_ATTR, H5E_BADITER, NULL, "can't locate attribute") /* Protect the object header to iterate over */ @@ -630,29 +639,37 @@ H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type, /* Find out whether it has already been opened. If it has, close the object * and make a copy of the already opened object to share the object info. */ - if(ret_value) { - if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, ret_value->shared->name)) < 0) + if(opened_attr) { + if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, opened_attr->shared->name)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "failed in finding opened attribute") /* If found that the attribute is already opened, make a copy of it * and close the object just opened. */ if(found_open_attr && exist_attr) { - if(H5A_close(ret_value) < 0) + if(H5A_close(opened_attr) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute") - if(NULL == (ret_value = H5A_copy(NULL, exist_attr))) + if(NULL == (opened_attr = H5A_copy(NULL, exist_attr))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute") } else { /* Mark datatype as being on disk now */ - if(H5T_set_loc(ret_value->shared->dt, loc->file, H5T_LOC_DISK) < 0) + if(H5T_set_loc(opened_attr->shared->dt, loc->file, H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "invalid datatype location") } /* end if */ } /* end if */ + /* Set return value */ + ret_value = opened_attr; + done: if(oh && H5O_unprotect(loc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_ATTR, H5E_CANTUNPROTECT, NULL, "unable to release object header") + /* Release any resources, on error */ + if(NULL == ret_value && opened_attr) + if(H5A_close(opened_attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_attr_open_by_idx() */ |