diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-23 07:11:57 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-23 07:11:57 (GMT) |
commit | 346d487d16f9f7bca6e5bce758bab1c14b20b9ef (patch) | |
tree | 845153c2bb62de2f098abaea5d293532b6c63340 /src/H5FL.c | |
parent | ab37aae39f7754827774577a0053e1b0979b3b1d (diff) | |
download | hdf5-346d487d16f9f7bca6e5bce758bab1c14b20b9ef.zip hdf5-346d487d16f9f7bca6e5bce758bab1c14b20b9ef.tar.gz hdf5-346d487d16f9f7bca6e5bce758bab1c14b20b9ef.tar.bz2 |
[svn-r18160] Description:
Bring r18159 from trunk to 1.8 branch:
Bring Coverity fixes from 1/22/10 session to trunk:
r18137:
219: Initialized hid_t to -1 and added close to error block.
189-191: Initialized line to NULL and added free line, and close fp to error block.
r18138:
19: Moved code block for printing that the number of enums is empty to the error block. (Would never have been executed otherwise)
r18139:
Fix coverity item 58. Moved code related to displaying the parent of a repeated
group to the else(isRoot) section, as the root group has no parent.
r18140:
218: Initialized ret_value variable to -1. Because of throw Exception in default case of switch, the coverity problem would not have executed anyway. Good pratice is to initialize variables.
r18141:
Fix coverity item 92. Added code to H5E_register_class to free cls in case of
an error.
r18142:
Fix coverity item 91. Added code to H5E_create_msg to free msg in case of an
error.
r18143:
fixed issue 14,
took away "if" and used #ifndef_xxx.
r18144:
Fix coverity item 110. Added code to H5Eget_minor to free msg_str in case of
an error.
r18145:
fixed coverity #18 removed "aligned", it is always NULL.
r18146:
Fix coverity item 109. Added code to H5Eget_major to free msg_str in case of
an error.
r18147:
Fixed coverity #81 and #82, Check for bad pointer(s), but can't issue error, just leave
r18148:
Fix coverity item 97. Added code to H5FD_fapl_open to free copied_driver_info
in case of an error.
r18149:
Fix coverity item 96. Added code to H5FD_dxpl_open to free copied_driver_info
in case of an error.
r18150:
Fix Coverity issue #29: Protected cache_ptr dereferences with "if(pass)"
block
r18151:
Fix coverity item 93. Added code to H5FL_fac_init to free factory and new_node
in case of an error.
r18152:
Fix coverity items 98 and 99. Added code free allocated space in case of
error.
r18155:
124: Freed head pointer before jumping to done. There was no error handling block and normal exit used same path out.
120-123: Freed list of lists in error handling block.
r18156:
Fix coverity issues 179, 180, 181, 182, 183, 184, 186, 320, 407. These were resource leak issues where allocated memory was not freed, generally in the case of tests that failed.
Tested on:
Mac OS X/32 10.6.2 (amazon) debug & production
Diffstat (limited to 'src/H5FL.c')
-rw-r--r-- | src/H5FL.c | 55 |
1 files changed, 31 insertions, 24 deletions
@@ -380,7 +380,7 @@ H5FL_reg_malloc(H5FL_reg_head_t *head H5FL_TRACK_PARAMS) /* Make certain the list is initialized first */ if(!head->init) if(H5FL_reg_init(head)<0) - HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'regular' blocks") + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'regular' blocks") /* Check for nodes available on the free list first */ if(head->list!=NULL) { @@ -399,7 +399,7 @@ H5FL_reg_malloc(H5FL_reg_head_t *head H5FL_TRACK_PARAMS) /* Otherwise allocate a node */ else { if (NULL==(ret_value = H5FL_malloc(head->size))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Increment the number of blocks allocated in list */ head->allocated++; @@ -456,7 +456,7 @@ H5FL_reg_calloc(H5FL_reg_head_t *head H5FL_TRACK_PARAMS) /* Allocate the block */ if (NULL==(ret_value = H5FL_reg_malloc(head H5FL_TRACK_INFO_INT))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Clear to zeros */ /* (Accomodate tracking information, if present) */ @@ -864,7 +864,7 @@ H5FL_blk_malloc(H5FL_blk_head_t *head, size_t size H5FL_TRACK_PARAMS) /* Make certain the list is initialized first */ if(!head->init) if(H5FL_blk_init(head)<0) - HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'block' list") + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'block' list") /* check if there is a free list for blocks of this size */ /* and if there are any blocks available on the list */ @@ -953,7 +953,7 @@ H5FL_blk_calloc(H5FL_blk_head_t *head, size_t size H5FL_TRACK_PARAMS) /* Allocate the block */ if (NULL==(ret_value = H5FL_blk_malloc(head,size H5FL_TRACK_INFO_INT))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Clear the block to zeros */ HDmemset(ret_value,0,size); @@ -1335,7 +1335,7 @@ H5FL_arr_init(H5FL_arr_head_t *head) /* Allocate a new garbage collection node */ if(NULL == (new_node = (H5FL_gc_arr_node_t *)H5MM_malloc(sizeof(H5FL_gc_arr_node_t)))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Initialize the new garbage collection node */ new_node->list = head; @@ -1346,7 +1346,7 @@ H5FL_arr_init(H5FL_arr_head_t *head) /* Allocate room for the free lists */ if(NULL == (head->list_arr = (H5FL_arr_node_t *)H5MM_calloc((size_t)head->maxelem*sizeof(H5FL_arr_node_t)))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Initialize the size of each array */ for(u = 0; u < (size_t)head->maxelem; u++) @@ -1469,7 +1469,7 @@ H5FL_arr_malloc(H5FL_arr_head_t *head, size_t elem) /* Make certain the list is initialized first */ if(!head->init) if(H5FL_arr_init(head)<0) - HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'array' blocks") + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'array' blocks") /* Sanity check that the number of elements is supported */ HDassert(elem<=(unsigned) head->maxelem); @@ -1496,7 +1496,7 @@ H5FL_arr_malloc(H5FL_arr_head_t *head, size_t elem) /* Otherwise allocate a node */ else { if(NULL == (new_obj = (H5FL_arr_list_t *)H5FL_malloc(sizeof(H5FL_arr_list_t)+mem_size))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Increment the number of blocks allocated in list */ head->allocated++; @@ -1540,11 +1540,11 @@ H5FL_arr_calloc(H5FL_arr_head_t *head, size_t elem) HDassert(elem); /* Allocate the array */ - if (NULL==(ret_value = H5FL_arr_malloc(head,elem))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if(NULL == (ret_value = H5FL_arr_malloc(head, elem))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Clear to zeros */ - HDmemset(ret_value,0,head->list_arr[elem].size); + HDmemset(ret_value, 0, head->list_arr[elem].size); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1938,21 +1938,21 @@ done: H5FL_fac_head_t * H5FL_fac_init(size_t size) { - H5FL_fac_gc_node_t *new_node; /* Pointer to the node for the new list to garbage collect */ - H5FL_fac_head_t *factory; /* Pointer to new block factory */ + H5FL_fac_gc_node_t *new_node = NULL; /* Pointer to the node for the new list to garbage collect */ + H5FL_fac_head_t *factory = NULL; /* Pointer to new block factory */ H5FL_fac_head_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5FL_fac_init, NULL) /* Sanity check */ - HDassert(size>0); + HDassert(size > 0); /* Allocate room for the new factory */ if(NULL == (factory = (H5FL_fac_head_t *)H5FL_CALLOC(H5FL_fac_head_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for factory object") /* Set size of blocks for factory */ - factory->size=size; + factory->size = size; /* Allocate a new garbage collection node */ if(NULL == (new_node = (H5FL_fac_gc_node_t *)H5FL_MALLOC(H5FL_fac_gc_node_t))) @@ -1962,15 +1962,15 @@ H5FL_fac_init(size_t size) new_node->list = factory; /* Link in to the garbage collection list */ - new_node->next=H5FL_fac_gc_head.first; - H5FL_fac_gc_head.first=new_node; + new_node->next = H5FL_fac_gc_head.first; + H5FL_fac_gc_head.first = new_node; if(new_node->next) new_node->next->list->prev_gc=new_node; /* The new factory's prev_gc field will be set to NULL */ /* Make certain that the space allocated is large enough to store a free list pointer (eventually) */ - if(factory->size<sizeof(H5FL_fac_node_t)) - factory->size=sizeof(H5FL_fac_node_t); + if(factory->size < sizeof(H5FL_fac_node_t)) + factory->size = sizeof(H5FL_fac_node_t); /* Make certain there's room for tracking information, if any */ #ifdef H5FL_TRACK @@ -1978,12 +1978,19 @@ H5FL_fac_init(size_t size) #endif /* H5FL_TRACK */ /* Indicate that the free list is initialized */ - factory->init=1; + factory->init = 1; /* Set return value */ - ret_value=factory; + ret_value = factory; done: + if(!ret_value) { + if(factory) + factory = H5FL_FREE(H5FL_fac_head_t, factory); + if(new_node) + new_node = H5FL_FREE(H5FL_fac_gc_node_t, new_node); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5FL_fac_init() */ @@ -2123,7 +2130,7 @@ H5FL_fac_malloc(H5FL_fac_head_t *head H5FL_TRACK_PARAMS) /* Otherwise allocate a node */ else { if (NULL==(ret_value = H5FL_malloc(head->size))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Increment the number of blocks allocated in list */ head->allocated++; @@ -2184,7 +2191,7 @@ H5FL_fac_calloc(H5FL_fac_head_t *head H5FL_TRACK_PARAMS) /* Allocate the block */ if (NULL==(ret_value = H5FL_fac_malloc(head H5FL_TRACK_INFO_INT))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Clear to zeros */ /* (Accomodate tracking information, if present) */ |