summaryrefslogtreecommitdiffstats
path: root/fortran/src/H5Af.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-01-23 04:39:40 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-01-23 04:39:40 (GMT)
commitfcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0 (patch)
treea18fedef2b670c044913622650ef581dedce7ee1 /fortran/src/H5Af.c
parent2c872f398b3824c416d42f2018c3d3ea0c40e80f (diff)
downloadhdf5-fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0.zip
hdf5-fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0.tar.gz
hdf5-fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0.tar.bz2
[svn-r18157] Description:
Bring back changes from Coverity session on 1/15/10: r18111: Fix Coverity issue #130: make certain that the cache gets freed on error. r18112: Fix Coverity issue #43 by making cache testing calls protected by 'pass' variable. r18113: Fix Coverity issue #129 by releasing the cache on error. r18115: Coverity #45 fix: patched an error check in H5Screate_simple to prevent future dereferencing of a NULL point. Added a verification in test/th5s.c. r18116: Fix Coverity issue #43 by releasing cache on error. r18117: Coverity #362,363 by adding HGOTO_DONE, freeing allocations and associated changes. REsolving coverity results #364-368, 369, 370-372, 377, 379, and 380. r18118: Fix Coverity issue #42: assert that cache & test specification pointer are valid. r18122: Coverity #362,363 by adding HGOTO_DONE and freeing allocations. This also takes care of #357,358. r18123: Coverity #359-361, 373-376: Added HGOTO_DONE(FAIL) statement after checking allocation for NULL. Verified allocation is freed in done block. r18128: Fixed coverity issue #10 -- removed dead code. Tested on: Mac OS X/32 10.6.2 (amazon)
Diffstat (limited to 'fortran/src/H5Af.c')
-rw-r--r--fortran/src/H5Af.c123
1 files changed, 57 insertions, 66 deletions
diff --git a/fortran/src/H5Af.c b/fortran/src/H5Af.c
index 37718b9..939fd81 100644
--- a/fortran/src/H5Af.c
+++ b/fortran/src/H5Af.c
@@ -1196,32 +1196,27 @@ nh5adelete_by_idx_c (hid_t_f *loc_id, _fcd obj_name, size_t_f *obj_namelen,
int_f *idx_type, int_f *order, hsize_t_f *n, hid_t_f *lapl_id)
{
char *c_obj_name = NULL; /* Buffer to hold C string */
- H5_index_t c_idx_type;
- H5_iter_order_t c_order;
int_f ret_value = 0; /* Return value */
/*
* Convert FORTRAN name to C name
*/
- if((c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)) == NULL)
- HGOTO_DONE(FAIL);
-
- c_idx_type = (H5_index_t)*idx_type;
- c_order = (H5_iter_order_t)*order;
+ if(NULL == (c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)))
+ HGOTO_DONE(FAIL)
/*
* Call H5Adelete_by_name function.
*/
-
- if(H5Adelete_by_idx((hid_t)*loc_id, c_obj_name, c_idx_type, c_order, (hsize_t)*n, (hid_t)*lapl_id) < 0)
- HGOTO_DONE(FAIL);
-
+ if(H5Adelete_by_idx((hid_t)*loc_id, c_obj_name, (H5_index_t)*idx_type, (H5_iter_order_t)*order, (hsize_t)*n, (hid_t)*lapl_id) < 0)
+ HGOTO_DONE(FAIL)
done:
if(c_obj_name)
HDfree(c_obj_name);
+
return ret_value;
}
+
/*----------------------------------------------------------------------------
* Name: h5aget_name_by_idx_c
* Purpose: Call h5aget_name_by_idx
@@ -1264,45 +1259,43 @@ nh5aget_name_by_idx_c (hid_t_f *loc_id, _fcd obj_name, size_t_f *obj_namelen,
size_t_f *size, hid_t_f *lapl_id)
{
char *c_obj_name = NULL; /* Buffer to hold C string */
- H5_index_t c_idx_type;
- H5_iter_order_t c_order;
- int_f ret_value = -1; /* Return value */
ssize_t c_size;
size_t c_buf_size;
- char *c_buf =NULL;
- /*
- * Convert FORTRAN name to C name
- */
- if((c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)) == NULL)
- HGOTO_DONE(FAIL);
+ char *c_buf = NULL;
+ int_f ret_value = 0; /* Return value */
- c_idx_type = (H5_index_t)*idx_type;
- c_order = (H5_iter_order_t)*order;
+ /*
+ * Convert FORTRAN name to C name
+ */
+ if(NULL == (c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)))
+ HGOTO_DONE(FAIL)
/*
* Allocate buffer to hold name of an attribute
*/
c_buf_size = (size_t)*size + 1;
- c_buf = (char *)HDmalloc(c_buf_size);
- if (c_buf == NULL) return ret_value;
+ if(NULL == (c_buf = (char *)HDmalloc(c_buf_size)))
+ HGOTO_DONE(FAIL)
+
/*
* Call H5Aget_name_by_idx function.
*/
- c_size = H5Aget_name_by_idx((hid_t)*loc_id, c_obj_name, c_idx_type, c_order, (hsize_t)*n, c_buf, c_buf_size,(hid_t)*lapl_id);
+ c_size = H5Aget_name_by_idx((hid_t)*loc_id, c_obj_name, (H5_index_t)*idx_type, (H5_iter_order_t)*order, (hsize_t)*n, c_buf, c_buf_size,(hid_t)*lapl_id);
+ if(c_size < 0)
+ HGOTO_DONE(FAIL)
- if (c_size < 0) goto done;
/*
* Convert C name to FORTRAN and place it in the given buffer
*/
- HD5packFstring(c_buf, _fcdtocp(name), c_buf_size-1);
+ HD5packFstring(c_buf, _fcdtocp(name), c_buf_size - 1);
*size = (size_t_f)c_size;
- ret_value = 0;
done:
if(c_obj_name)
- HDfree(c_obj_name);
- HDfree(c_buf);
+ HDfree(c_obj_name);
+ if(c_buf)
+ HDfree(c_buf);
return ret_value;
}
@@ -1339,27 +1332,24 @@ nh5aopen_by_idx_c (hid_t_f *loc_id, _fcd obj_name, size_t_f *obj_namelen,
int_f *idx_type, int_f *order, hsize_t_f *n, hid_t_f *aapl_id, hid_t_f *lapl_id, hid_t_f *attr_id )
{
char *c_obj_name = NULL; /* Buffer to hold C string */
- H5_index_t c_idx_type;
- H5_iter_order_t c_order;
int_f ret_value = 0; /* Return value */
- /*
- * Convert FORTRAN name to C name
- */
- if((c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)) == NULL)
- HGOTO_DONE(FAIL);
-
- c_idx_type = (H5_index_t)*idx_type;
- c_order = (H5_iter_order_t)*order;
+ /*
+ * Convert FORTRAN name to C name
+ */
+ if(NULL == (c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)))
+ HGOTO_DONE(FAIL)
/*
* Call H5Aopen_by_idx function.
*/
- if((*attr_id = (hid_t_f)H5Aopen_by_idx((hid_t)*loc_id, c_obj_name, c_idx_type, c_order, (hsize_t)*n, (hid_t)*aapl_id, (hid_t)*lapl_id)) < 0)
- HGOTO_DONE(FAIL);
+ if((*attr_id = (hid_t_f)H5Aopen_by_idx((hid_t)*loc_id, c_obj_name, (H5_index_t)*idx_type, (H5_iter_order_t)*order, (hsize_t)*n, (hid_t)*aapl_id, (hid_t)*lapl_id)) < 0)
+ HGOTO_DONE(FAIL)
+
done:
if(c_obj_name)
HDfree(c_obj_name);
+
return ret_value;
}
@@ -1445,36 +1435,34 @@ nh5aget_info_by_idx_c (hid_t_f *loc_id, _fcd obj_name, size_t_f *obj_namelen,
int_f *cset, hsize_t_f *data_size )
{
char *c_obj_name = NULL; /* Buffer to hold C string */
- H5_index_t c_idx_type;
- H5_iter_order_t c_order;
- int_f ret_value = 0; /* Return value */
H5A_info_t ainfo;
+ int_f ret_value = 0; /* Return value */
/*
* Convert FORTRAN name to C name
*/
- if((c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)) == NULL)
- HGOTO_DONE(FAIL);
+ if(NULL == (c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)))
+ HGOTO_DONE(FAIL)
- c_idx_type = (H5_index_t)*idx_type;
- c_order = (H5_iter_order_t)*order;
/*
* Call H5Ainfo_by_idx function.
*/
- if(H5Aget_info_by_idx((hid_t)*loc_id, c_obj_name, c_idx_type, c_order, (hsize_t)*n,
- &ainfo, (hid_t)*lapl_id) < 0)
- HGOTO_DONE(FAIL);
+ if(H5Aget_info_by_idx((hid_t)*loc_id, c_obj_name, (H5_index_t)*idx_type, (H5_iter_order_t)*order, (hsize_t)*n,
+ &ainfo, (hid_t)*lapl_id) < 0)
+ HGOTO_DONE(FAIL)
/* Unpack the structure */
-
*corder_valid = 0;
- if(ainfo.corder_valid > 0) *corder_valid = 1;
-
+ if(ainfo.corder_valid > 0)
+ *corder_valid = 1;
*corder = (int_f)ainfo.corder;
*cset = (int_f)ainfo.cset;
*data_size = (hsize_t)ainfo.data_size;
done:
+ if(c_obj_name)
+ HDfree(c_obj_name);
+
return ret_value;
}
@@ -1506,34 +1494,37 @@ nh5aget_info_by_name_c (hid_t_f *loc_id, _fcd obj_name, size_t_f *obj_namelen,
{
char *c_obj_name = NULL; /* Buffer to hold C string */
char *c_attr_name = NULL; /* Buffer to hold C string */
- int_f ret_value = 0; /* Return value */
H5A_info_t ainfo;
+ int_f ret_value = 0; /* Return value */
/*
* Convert FORTRAN name to C name
*/
- if((c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)) == NULL)
- HGOTO_DONE(FAIL);
- if((c_attr_name = HD5f2cstring(attr_name, (size_t)*attr_namelen)) == NULL)
- HGOTO_DONE(FAIL);
+ if(NULL == (c_obj_name = HD5f2cstring(obj_name, (size_t)*obj_namelen)))
+ HGOTO_DONE(FAIL)
+ if(NULL == (c_attr_name = HD5f2cstring(attr_name, (size_t)*attr_namelen)))
+ HGOTO_DONE(FAIL)
/*
* Call H5Ainfo_by_name function.
*/
- if(H5Aget_info_by_name((hid_t)*loc_id, c_obj_name, c_attr_name,
- &ainfo, (hid_t)*lapl_id) < 0)
- HGOTO_DONE(FAIL);
+ if(H5Aget_info_by_name((hid_t)*loc_id, c_obj_name, c_attr_name, &ainfo, (hid_t)*lapl_id) < 0)
+ HGOTO_DONE(FAIL)
/* Unpack the structure */
-
*corder_valid = 0;
- if(ainfo.corder_valid > 0) *corder_valid = 1;
-
+ if(ainfo.corder_valid > 0)
+ *corder_valid = 1;
*corder = (int_f)ainfo.corder;
*cset = (int_f)ainfo.cset;
*data_size = (hsize_t)ainfo.data_size;
done:
+ if(c_obj_name)
+ HDfree(c_obj_name);
+ if(c_attr_name)
+ HDfree(c_attr_name);
+
return ret_value;
}