diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-02-27 20:08:03 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-02-27 20:08:03 (GMT) |
commit | d3a9b81fd06423cb81c8f4fa49f2e4c265a9c3d0 (patch) | |
tree | 31816c1a7204c609ae6e7ea3e8b99ce518eaad87 /src/H5Spoint.c | |
parent | c90711e71362716cd9ab25d6b9167ca49edccfe8 (diff) | |
download | hdf5-d3a9b81fd06423cb81c8f4fa49f2e4c265a9c3d0.zip hdf5-d3a9b81fd06423cb81c8f4fa49f2e4c265a9c3d0.tar.gz hdf5-d3a9b81fd06423cb81c8f4fa49f2e4c265a9c3d0.tar.bz2 |
[svn-r18346] Description:
Bring Coverity fixes back from branch to trunk:
r18336:
Fix coverity issues 275, 276, 277, 323, 432, 433, and 434
r18337:
Fix Coverity issue #106: release free space section node on error
r18338:
Fixed Coverity #94 - In H5P_register, new_class wasn't closed when there's an
error after it's created.
r18339:
Fix Coverity #185 - In test_conv_str_1, BUF wasn't freed when there's an error
in this function.
r18340:
Correct error in r18337 that wasn't releasing indirect fractal heap block
early enough.
r18341:
Close nodes if any failed in the middle of allocating new nodes. Coverity 140
and 141
r18342:
Correct [another] problem w/r18337.
r18343:
Fix coverity items 185, 20, and 21.
r18344:
Fix Coverity 213 - In H5FD_family_close, the double pointer file->memb was
dereferenced without NULL checking
(We believe).
r18345:
Fix Coverity issue # 210; removed NULL check after pointer dereferenced in
H5HFdblock.c. Also assigned NULL to pointer in H5Pint.c to fix segmentation
fault.
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
Mac OS X/32 10.6.2 (amazon) in debug mode
Mac OS X/32 10.6.2 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
Diffstat (limited to 'src/H5Spoint.c')
-rw-r--r-- | src/H5Spoint.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/H5Spoint.c b/src/H5Spoint.c index 5f4c74d..d2e46cf 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -384,8 +384,8 @@ H5S_point_iter_release (H5S_sel_iter_t UNUSED * iter) static herr_t H5S_point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *coord) { - H5S_pnt_node_t *top, *curr, *new_node; /* Point selection nodes */ - unsigned i; /* Counter */ + H5S_pnt_node_t *top = NULL, *curr = NULL, *new_node = NULL; /* Point selection nodes */ + unsigned u; /* Counter */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5S_point_add) @@ -395,26 +395,27 @@ H5S_point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *co HDassert(coord); HDassert(op == H5S_SELECT_SET || op == H5S_SELECT_APPEND || op == H5S_SELECT_PREPEND); - top = curr = NULL; - for(i = 0; i < num_elem; i++) { + for(u = 0; u < num_elem; u++) { /* Allocate space for the new node */ if(NULL == (new_node = H5FL_MALLOC(H5S_pnt_node_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate point node") + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point node") + /* Initialize fields in node */ + new_node->next = NULL; if(NULL == (new_node->pnt = (hsize_t *)H5MM_malloc(space->extent.rank * sizeof(hsize_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate coordinate information") + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate coordinate information") /* Copy over the coordinates */ - HDmemcpy(new_node->pnt, coord + (i * space->extent.rank), (space->extent.rank * sizeof(hsize_t))); + HDmemcpy(new_node->pnt, coord + (u * space->extent.rank), (space->extent.rank * sizeof(hsize_t))); /* Link into list */ - new_node->next = NULL; if(top == NULL) top = new_node; else curr->next = new_node; curr = new_node; } /* end for */ + new_node = NULL; /* Insert the list of points selected in the proper place */ if(op == H5S_SELECT_SET || op == H5S_SELECT_PREPEND) { @@ -426,13 +427,15 @@ H5S_point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *co space->select.sel_info.pnt_lst->head = top; } /* end if */ else { /* op==H5S_SELECT_APPEND */ - new_node = space->select.sel_info.pnt_lst->head; - if(new_node != NULL) { - while(new_node->next != NULL) - new_node = new_node->next; + H5S_pnt_node_t *tmp_node; /* Temporary point selection node */ + + tmp_node = space->select.sel_info.pnt_lst->head; + if(tmp_node != NULL) { + while(tmp_node->next != NULL) + tmp_node = tmp_node->next; /* Append new list to point selection */ - new_node->next = top; + tmp_node->next = top; } /* end if */ else space->select.sel_info.pnt_lst->head = top; @@ -445,6 +448,20 @@ H5S_point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *co space->select.num_elem += num_elem; done: + if(ret_value < 0) { + /* Release possibly partially initialized new node */ + if(new_node) + new_node = H5FL_FREE(H5S_pnt_node_t, new_node); + + /* Release possible linked list of nodes */ + while(top) { + curr = top->next; + H5MM_xfree(top->pnt); + top = H5FL_FREE(H5S_pnt_node_t, top); + top = curr; + } /* end while */ + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* H5S_point_add() */ @@ -477,20 +494,19 @@ H5S_point_release (H5S_t *space) HDassert(space); /* Delete all the nodes from the list */ - curr=space->select.sel_info.pnt_lst->head; - while(curr!=NULL) { - next=curr->next; + curr = space->select.sel_info.pnt_lst->head; + while(curr != NULL) { + next = curr->next; H5MM_xfree(curr->pnt); - (void)H5FL_FREE(H5S_pnt_node_t, curr); - curr=next; + curr = H5FL_FREE(H5S_pnt_node_t, curr); + curr = next; } /* end while */ /* Free & reset the point list header */ - (void)H5FL_FREE(H5S_pnt_list_t, space->select.sel_info.pnt_lst); - space->select.sel_info.pnt_lst=NULL; + space->select.sel_info.pnt_lst = H5FL_FREE(H5S_pnt_list_t, space->select.sel_info.pnt_lst); /* Reset the number of elements in the selection */ - space->select.num_elem=0; + space->select.num_elem = 0; FUNC_LEAVE_NOAPI(SUCCEED) } /* H5S_point_release() */ |