summaryrefslogtreecommitdiffstats
path: root/src/H5Oefl.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-02-15 03:23:19 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-02-15 03:23:19 (GMT)
commitc5c0afaa613115284c4d564a574a13b97027c1ab (patch)
tree98561ce374f7bd333ede4dc721c291fc2b597ea4 /src/H5Oefl.c
parent824d691cbf1a04e3207218e86246645b5609079e (diff)
downloadhdf5-c5c0afaa613115284c4d564a574a13b97027c1ab.zip
hdf5-c5c0afaa613115284c4d564a574a13b97027c1ab.tar.gz
hdf5-c5c0afaa613115284c4d564a574a13b97027c1ab.tar.bz2
[svn-r18256] Description:
Bring changes from Coverity fixing branch to trunk: r18235: Fixed coverity 114: if (NULL ==_dest) H5MM_free(dest); r18236: Close Coverity issue #28 (again :-) by working through the logic of the routine more thoroughly to eliminate the goto statements. (LK & QK) r18237: fixed coverity 133: if (NULL==_dest && NULL==ret_value && NULL != dest) H5MM_free(dest); r18238: Fix coverity items 421 and 422. Added assertion that the heap's free list is NULL when entering H5HL_fl_deserialize, guarateeing that the free list will always be linked in even on failure. r18239: Fix coverity item 268. Changed H5MM_xfree(read_buf) to read_buf = H5MM_xfree(read_buf) so that read_buf isn't manipulated after it's been freed. r18241: coverity fix: use correct free functon H5FL_FREE()from the previous fix r18242: Coverity fix 139: Free dst correctly in H5O_sdspace_copy(). r18243: Fix Coverity issue #417 by checking for NULL return value from setup_cache() (LK & QK) r18244: Coverity Fix 132: free dest correctly in H5O_efl_copy() r18245: Issue 121: H5S_hyper_make_spans() cannot deal with counts of 0. However, H5Sselect_hyperslab() API does allow a count of 0. Therefore, simply throw an error if this function encounters a count of 0. r18246: Check file_ptr to address coverity issue # 418 r18247: Fixed coverity 113: if (sequence) H5MM_xfree(sequence); r18248: Coverity issue #414 by checking for NULL return from setup_cache() (LK & QK) r18249: fixed coverity 274: moved H5FL_FREE(H5A_t, attr); to a line above so that if attr is null, it will not free it. r18250: Fix coverity issue #86. Check return of malloc function to ensure non-null before continuing. Tested on: Mac OS X/32 10.6.2 (amazon) w/debug & production) (h5committested in daily tests on branch)
Diffstat (limited to 'src/H5Oefl.c')
-rw-r--r--src/H5Oefl.c58
1 files changed, 45 insertions, 13 deletions
diff --git a/src/H5Oefl.c b/src/H5Oefl.c
index 0eb4ba2..25cac88 100644
--- a/src/H5Oefl.c
+++ b/src/H5Oefl.c
@@ -262,27 +262,58 @@ H5O_efl_copy(const void *_mesg, void *_dest)
/* check args */
HDassert(mesg);
if(!dest) {
- if(NULL == (dest = (H5O_efl_t *)H5MM_calloc(sizeof(H5O_efl_t))) ||
- NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_malloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- } else if(dest->nalloc < mesg->nalloc) {
- H5MM_xfree(dest->slot);
- if(NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_malloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- }
+ if(NULL == (dest = (H5O_efl_t *)H5MM_calloc(sizeof(H5O_efl_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message")
+ if(NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_calloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots")
+ } /* end if */
+ else if(dest->nalloc < mesg->nalloc) {
+ H5O_efl_entry_t *temp_slot; /* Temporary pointer to new slot information */
+
+ /* Allocate new 'slot' information */
+ if(NULL == (temp_slot = (H5O_efl_entry_t *)H5MM_calloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots")
+
+ /* Release old 'slot' information */
+ for(u = 0; u < dest->nused; u++)
+ dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
+ dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot);
+
+ /* Point to new 'slot' information */
+ dest->slot = temp_slot;
+ } /* end if */
+ else {
+ /* Release old 'slot' information */
+ for(u = 0; u < dest->nused; u++)
+ dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
+ } /* end else */
dest->heap_addr = mesg->heap_addr;
dest->nalloc = mesg->nalloc;
dest->nused = mesg->nused;
for(u = 0; u < mesg->nused; u++) {
dest->slot[u] = mesg->slot[u];
- dest->slot[u].name = H5MM_xstrdup(mesg->slot[u].name);
+ if(NULL == (dest->slot[u].name = H5MM_xstrdup(mesg->slot[u].name)))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slot name")
} /* end for */
/* Set return value */
ret_value = dest;
done:
+ if(NULL == ret_value) {
+ if(dest && NULL == _dest) {
+ if(dest->slot) {
+ for(u = 0; u < mesg->nused; u++) {
+ if(dest->slot[u].name != NULL && dest->slot[u].name != mesg->slot[u].name)
+ dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
+ } /* end for */
+ dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot);
+ } /* end if */
+ dest = (H5O_efl_t *)H5MM_xfree(dest);
+ } /* end if */
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_efl_copy() */
@@ -353,12 +384,13 @@ H5O_efl_reset(void *_mesg)
HDassert(mesg);
/* reset */
- for(u = 0; u < mesg->nused; u++)
- mesg->slot[u].name = (char *)H5MM_xfree(mesg->slot[u].name);
+ if(mesg->slot) {
+ for(u = 0; u < mesg->nused; u++)
+ mesg->slot[u].name = (char *)H5MM_xfree(mesg->slot[u].name);
+ mesg->slot = (H5O_efl_entry_t *)H5MM_xfree(mesg->slot);
+ } /* end if */
mesg->heap_addr = HADDR_UNDEF;
mesg->nused = mesg->nalloc = 0;
- if(mesg->slot)
- mesg->slot = (H5O_efl_entry_t *)H5MM_xfree(mesg->slot);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5O_efl_reset() */