summaryrefslogtreecommitdiffstats
path: root/src/H5MP.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-02-20 02:23:44 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-02-20 02:23:44 (GMT)
commit0c39a78927ae1e4b7471f96743a8cf5dd30350b0 (patch)
tree21eb68c066d6ef8a139278439d02c89202ce970f /src/H5MP.c
parent7bac0bb48dd18809fa015e91848dc8756c0fe536 (diff)
downloadhdf5-0c39a78927ae1e4b7471f96743a8cf5dd30350b0.zip
hdf5-0c39a78927ae1e4b7471f96743a8cf5dd30350b0.tar.gz
hdf5-0c39a78927ae1e4b7471f96743a8cf5dd30350b0.tar.bz2
[svn-r18300] Description:
Bring Coverity fixes from branch to trunk: r18282: Fix Coverity issue #428 by wrapping testing calls with if(pass) {} block. r18283: Fix Coverity issue #425 by wrapping test calls in if(pass) {} block r18284: Issue 166: init_error() malloc'd 3 pointers in initialization and never freed inc ase of errors. Init pointers to NULL, check allocation results and free allocations in error block r18285: Fix Coverity issue #410 by wrapping test calls with if(pass) {} block. r18286: Issue 165: custom_print_cb() needed allocations freed in error block. r18287: Fix coverity issue # 409 Added if (pass) checks around calls to flush_cache. Additionally, added a check for file_ptr = NULL after call to setup_cache. r18288: Fix coverity# 107 free fh in H5HF_close() correctly before exit the function even when failure occurs. r18289: Fix Coverity issue #429: correct failure return values to match return type from routine. r18290: Fix Coverity issue #103: release allocated indirect section on error r18294: Issue 153, 152: Check allocations and free allocations in error block. Also cleaned up hid_t identifer that were opened in error block. r18295: Fix coverity# 101 free new_loc in H5HF_man_iter_start_entry() correctly before exit the function even when failure occurs r18296: Fix coverity# 100 free down_loc in H5HF_man_iter_down() before exit the function when failure occurs r18297: Fixed coverity issues 54, 55 and 216. Correctly handle the various ways that allocation of attr_name can fail in test_attr_basic_write. r18298: Fix coverity# 119 free object in H5HG_read() before exit the function when failure occurs r18299: Fix coverity issue #112: Add cleanup during error handling of H5MP_create. Tested on: Mac OS X/32 10.6.2 (amazon) w/debug & production Misc. Linux configurations (on original checkins)
Diffstat (limited to 'src/H5MP.c')
-rw-r--r--src/H5MP.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/H5MP.c b/src/H5MP.c
index 63a65ae..dd54316 100644
--- a/src/H5MP.c
+++ b/src/H5MP.c
@@ -87,16 +87,16 @@ H5FL_DEFINE(H5MP_pool_t);
*-------------------------------------------------------------------------
*/
H5MP_pool_t *
-H5MP_create (size_t page_size, unsigned flags)
+H5MP_create(size_t page_size, unsigned flags)
{
- H5MP_pool_t *mp; /* New memory pool header */
+ H5MP_pool_t *mp = NULL; /* New memory pool header */
H5MP_pool_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5MP_create, NULL)
/* Allocate space for the pool header */
- if (NULL==(mp = H5FL_MALLOC(H5MP_pool_t)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for memory pool header")
+ if(NULL == (mp = H5FL_MALLOC(H5MP_pool_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for memory pool header")
/* Assign information */
mp->page_size = H5MP_BLOCK_ALIGN(page_size);
@@ -108,13 +108,17 @@ H5MP_create (size_t page_size, unsigned flags)
mp->max_size = mp->page_size - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t));
/* Create factory for pool pages */
- if((mp->page_fac=H5FL_fac_init(page_size))==NULL)
- HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't create page factory")
+ if(NULL == (mp->page_fac = H5FL_fac_init(page_size)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, NULL, "can't create page factory")
/* Set return value */
ret_value = mp;
done:
+ if(NULL == ret_value && mp)
+ if(H5MP_close(mp) < 0)
+ HDONE_ERROR(H5E_RESOURCE, H5E_CANTFREE, NULL, "unable to free memory pool header")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MP_create() */
@@ -271,7 +275,7 @@ HDfprintf(stderr,"%s: request = %Zu, needed = %Zu\n", FUNC, request, needed);
/* Allocate new page */
if(NULL == (alloc_page = H5MP_new_page(mp, page_size)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for page")
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for page")
/* Set the block to allocate from */
alloc_free = alloc_page->free_blk;
@@ -343,7 +347,7 @@ done:
*-------------------------------------------------------------------------
*/
void *
-H5MP_free (H5MP_pool_t *mp, void *spc)
+H5MP_free(H5MP_pool_t *mp, void *spc)
{
H5MP_page_blk_t *spc_blk; /* Block for space to free */
H5MP_page_t *spc_page; /* Page containing block to free */
@@ -430,7 +434,7 @@ HDfprintf(stderr,"%s: Freeing from page = %p\n", "H5MP_free", spc_page);
*-------------------------------------------------------------------------
*/
herr_t
-H5MP_close (H5MP_pool_t *mp)
+H5MP_close(H5MP_pool_t *mp)
{
herr_t ret_value = SUCCEED; /* Return value */
@@ -447,9 +451,9 @@ H5MP_close (H5MP_pool_t *mp)
/* Free the page appropriately */
if(page->fac_alloc)
- H5FL_FAC_FREE(mp->page_fac,page);
+ page = H5FL_FAC_FREE(mp->page_fac, page);
else
- H5MM_xfree(page);
+ page = H5MM_xfree(page);
page = next_page;
} /* end while */
@@ -457,13 +461,13 @@ H5MP_close (H5MP_pool_t *mp)
/* Release page factory */
if(mp->page_fac)
- if(H5FL_fac_term(mp->page_fac)<0)
- HGOTO_ERROR (H5E_RESOURCE, H5E_CANTRELEASE, FAIL, "can't destroy page factory")
+ if(H5FL_fac_term(mp->page_fac) < 0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTRELEASE, FAIL, "can't destroy page factory")
+done:
/* Free the memory pool itself */
- (void)H5FL_FREE(H5MP_pool_t, mp);
+ mp = H5FL_FREE(H5MP_pool_t, mp);
-done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MP_close() */