diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-15 03:05:59 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-15 03:05:59 (GMT) |
commit | 066294e32131d1d81d326d35d67b0d753e8b8b56 (patch) | |
tree | ff8ac3f4d94edceeacf167486a8a9f7adcd01d63 /src/H5HG.c | |
parent | 22da4232a4693e3f0a4ee2f37053f85a28e885fd (diff) | |
download | hdf5-066294e32131d1d81d326d35d67b0d753e8b8b56.zip hdf5-066294e32131d1d81d326d35d67b0d753e8b8b56.tar.gz hdf5-066294e32131d1d81d326d35d67b0d753e8b8b56.tar.bz2 |
[svn-r18109] Description:
Bring r18076-18096 from hdf5_1_8_coverity branch to trunk:
r18076:
Correct Coverity issue #1 by removing dead code
r18077:
Fix coverity item 142. When an error occurred while copying a linked list in
H5S_point_copy, the library would not free the partially allocated list. Added
code to free the list in this case.
r18078:
Correct Coverity issue #2 by removing impossible to reach code.
r18079:
Correct #3 by removing impossible to reach code.
r18080:
Correct Coverity issue #4 by removing impossible to reach code.
r18081:
fix coverity 26 , check (dblik->parent) before calls H5HF_man_iblock_detach().
r18082:
Fixed coverity issues 321 and 316.
321: freed sm_buf in error handling to remove resource leak.
Also set sm_buf to NULL after other instances in which
it is freed to prevent double free.
316: initialized nmembs to 0.
r18083:
Correct Coverity issue #6 by removing debugging knob from error reporting code.
r18084:
Fix coverity item 269 + others. When a error occurred in a function using the
h5tools error framework, the "past_catch" variable would not be set to true
because that statement was before the label that goto jumped to. This could
cause a failure in the cleanup section to go back to the start of the section,
freeing variables twice, etc.
Moved the label infront of past_catch=TRUE.
r18085:
fixed coverity #27, check if (heap) before use heap->obj....
r18086:
fixed coverity #28, check curr_span not null before use it at if(curr_span &&
(io_bytes_left==0 || curr_seq>=maxseq))
r18087:
Correct Coverity issue #7 by cleaning up correctly on error
r18088:
Correct Coverity #8 by removing unchanged variable checking code.
r18089:
Correct Coverity issue #9 - remove impossible to reach code.
r18090:
Correct Coverity issue #11 by removing impossible to reach code. Also clean
up some minor style issues.
r18091:
Fix coverity items 314 and 318. Changed the improper assertion of the return
value of a library function to a check, and a return(void) on failure.
r18092:
Fix coverity item 70. Changed the improper assertion of the return value of a
library function to a check, and a return(void) on failure.
r18093:
Correct Coverity issue #12 by removing dead code.
r18094:
Correct Coverity issue #16 by removing debugging code.
r18095:
Fixed coverity issue # 271.
Removed redundant checking and freeing of sm_buf1 and sm_buf2.
r18096:
Correct Coverity issue #17 by refactoring test to remove dead code.
Also, removed previous "coverity" statements in comments, we'll review
those issues again and see if we can figure them out, now that we have more
experience with Coverity.
Tested on:
Mac OS X/32 10.6.2 (amazon)
Diffstat (limited to 'src/H5HG.c')
-rw-r--r-- | src/H5HG.c | 91 |
1 files changed, 46 insertions, 45 deletions
@@ -140,31 +140,28 @@ H5FL_BLK_DEFINE(gheap_chunk); *------------------------------------------------------------------------- */ static haddr_t -H5HG_create (H5F_t *f, hid_t dxpl_id, size_t size) +H5HG_create(H5F_t *f, hid_t dxpl_id, size_t size) { H5HG_heap_t *heap = NULL; uint8_t *p = NULL; haddr_t addr; size_t n; - haddr_t ret_value; /* Return value */ + haddr_t ret_value = HADDR_UNDEF; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5HG_create) /* Check args */ - assert (f); - if (size<H5HG_MINSIZE) + HDassert(f); + if(size < H5HG_MINSIZE) size = H5HG_MINSIZE; size = H5HG_ALIGN(size); /* Create it */ - H5_CHECK_OVERFLOW(size,size_t,hsize_t); - if ( HADDR_UNDEF== - (addr=H5MF_alloc(f, H5FD_MEM_GHEAP, dxpl_id, (hsize_t)size))) - HGOTO_ERROR (H5E_HEAP, H5E_CANTINIT, HADDR_UNDEF, \ - "unable to allocate file space for global heap"); - if (NULL==(heap = H5FL_MALLOC (H5HG_heap_t))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, \ - "memory allocation failed"); + H5_CHECK_OVERFLOW(size, size_t, hsize_t); + if(HADDR_UNDEF == (addr = H5MF_alloc(f, H5FD_MEM_GHEAP, dxpl_id, (hsize_t)size))) + HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, HADDR_UNDEF, "unable to allocate file space for global heap") + if(NULL == (heap = H5FL_MALLOC(H5HG_heap_t))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "memory allocation failed") heap->addr = addr; heap->size = size; @@ -185,14 +182,14 @@ HDmemset(heap->chunk, 0, size); *p++ = 0; /*reserved*/ *p++ = 0; /*reserved*/ *p++ = 0; /*reserved*/ - H5F_ENCODE_LENGTH (f, p, size); + H5F_ENCODE_LENGTH(f, p, size); /* * Padding so free space object is aligned. If malloc returned memory * which was always at least H5HG_ALIGNMENT aligned then we could just * align the pointer, but this might not be the case. */ - n = H5HG_ALIGN(p-heap->chunk) - (p-heap->chunk); + n = H5HG_ALIGN(p - heap->chunk) - (p - heap->chunk); #ifdef OLD_WAY /* Don't bother zeroing out the rest of the info in the heap -QAK */ HDmemset(p, 0, n); @@ -207,7 +204,7 @@ HDmemset(heap->chunk, 0, size); UINT16ENCODE(p, 0); /*object ID*/ UINT16ENCODE(p, 0); /*reference count*/ UINT32ENCODE(p, 0); /*reserved*/ - H5F_ENCODE_LENGTH (f, p, heap->obj[0].size); + H5F_ENCODE_LENGTH(f, p, heap->obj[0].size); #ifdef OLD_WAY /* Don't bother zeroing out the rest of the info in the heap -QAK */ HDmemset (p, 0, (size_t)((heap->chunk+heap->size) - p)); @@ -226,7 +223,7 @@ HDmemset(heap->chunk, 0, size); MIN(f->shared->ncwfs, H5HG_NCWFS - 1) * sizeof(H5HG_heap_t *)); f->shared->cwfs[0] = heap; f->shared->ncwfs = MIN(H5HG_NCWFS, f->shared->ncwfs+1); - } + } /* end else */ /* Add the heap to the cache */ if(H5AC_set(f, dxpl_id, H5AC_GHEAP, addr, heap, H5AC__NO_FLAGS_SET) < 0) @@ -235,9 +232,20 @@ HDmemset(heap->chunk, 0, size); ret_value = addr; done: - if(!(H5F_addr_defined(addr)) && heap) - if(H5HG_dest(f, heap) < 0) - HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, HADDR_UNDEF, "unable to destroy global heap collection") + /* Cleanup on error */ + if(!H5F_addr_defined(ret_value)) { + if(H5F_addr_defined(addr)) { + /* Release the space on disk */ + if(H5MF_xfree(f, H5FD_MEM_GHEAP, dxpl_id, addr, (hsize_t)size) < 0) + HDONE_ERROR(H5E_BTREE, H5E_CANTFREE, HADDR_UNDEF, "unable to free global heap") + + /* Check if the heap object was allocated */ + if(heap) + /* Destroy the heap object */ + if(H5HG_dest(f, heap) < 0) + HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, HADDR_UNDEF, "unable to destroy global heap collection") + } /* end if */ + } /* end if */ FUNC_LEAVE_NOAPI(ret_value); } /* H5HG_create() */ @@ -704,54 +712,47 @@ done: * Programmer: Robb Matzke * Monday, March 30, 1998 * - * Modifications: - * - * John Mainzer - 6/8/05 - * Modified function to use the dirtied parameter of - * H5AC_unprotect() instead of modifying the is_dirty - * field of the cache info. - * *------------------------------------------------------------------------- */ int -H5HG_link (H5F_t *f, hid_t dxpl_id, const H5HG_t *hobj, int adjust) +H5HG_link(H5F_t *f, hid_t dxpl_id, const H5HG_t *hobj, int adjust) { H5HG_heap_t *heap = NULL; unsigned heap_flags = H5AC__NO_FLAGS_SET; int ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5HG_link, FAIL); + FUNC_ENTER_NOAPI(H5HG_link, FAIL) /* Check args */ - assert (f); - assert (hobj); - if (0==(f->intent & H5F_ACC_RDWR)) + HDassert(f); + HDassert(hobj); + if(0 == (f->intent & H5F_ACC_RDWR)) HGOTO_ERROR(H5E_HEAP, H5E_WRITEERROR, FAIL, "no write intent on file") - if(adjust!=0) { - /* Load the heap */ - if (NULL == (heap = (H5HG_heap_t *)H5AC_protect(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL, H5AC_WRITE))) - HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap") - - assert (hobj->idx<heap->nused); - assert (heap->obj[hobj->idx].begin); - if (heap->obj[hobj->idx].nrefs+adjust<0) - HGOTO_ERROR (H5E_HEAP, H5E_BADRANGE, FAIL, "new link count would be out of range") - if (heap->obj[hobj->idx].nrefs+adjust>H5HG_MAXLINK) - HGOTO_ERROR (H5E_HEAP, H5E_BADVALUE, FAIL, "new link count would be out of range") + /* Load the heap */ + if(NULL == (heap = (H5HG_heap_t *)H5AC_protect(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL, H5AC_WRITE))) + HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap") + + if(adjust != 0) { + HDassert(hobj->idx < heap->nused); + HDassert(heap->obj[hobj->idx].begin); + if((heap->obj[hobj->idx].nrefs + adjust) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_BADRANGE, FAIL, "new link count would be out of range") + if((heap->obj[hobj->idx].nrefs + adjust) > H5HG_MAXLINK) + HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "new link count would be out of range") heap->obj[hobj->idx].nrefs += adjust; heap_flags |= H5AC__DIRTIED_FLAG; } /* end if */ /* Set return value */ - ret_value=heap->obj[hobj->idx].nrefs; + ret_value = heap->obj[hobj->idx].nrefs; done: if(heap && H5AC_unprotect(f, dxpl_id, H5AC_GHEAP, hobj->addr, heap, heap_flags) < 0) HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release object header") - FUNC_LEAVE_NOAPI(ret_value); -} + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5HG_link() */ /*------------------------------------------------------------------------- |