summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-01-23 07:11:57 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-01-23 07:11:57 (GMT)
commit346d487d16f9f7bca6e5bce758bab1c14b20b9ef (patch)
tree845153c2bb62de2f098abaea5d293532b6c63340 /src
parentab37aae39f7754827774577a0053e1b0979b3b1d (diff)
downloadhdf5-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')
-rw-r--r--src/H5E.c67
-rw-r--r--src/H5Edeprec.c36
-rw-r--r--src/H5Eint.c24
-rw-r--r--src/H5FD.c33
-rw-r--r--src/H5FL.c55
-rw-r--r--src/H5FS.c12
-rw-r--r--src/H5FSsection.c12
-rw-r--r--src/H5Lexternal.c4
-rw-r--r--src/H5Shyper.c119
9 files changed, 240 insertions, 122 deletions
diff --git a/src/H5E.c b/src/H5E.c
index 2d57cd6..8231d2f 100644
--- a/src/H5E.c
+++ b/src/H5E.c
@@ -361,6 +361,36 @@ H5E_get_stack(void)
/*-------------------------------------------------------------------------
+ * Function: H5E_free_class
+ *
+ * Purpose: Private function to free an error class.
+ *
+ * Return: Non-negative value on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Friday, January 22, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5E_free_class(H5E_cls_t *cls)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5E_free_class)
+
+ /* Check arguments */
+ HDassert(cls);
+
+ /* Free error class structure */
+ cls->cls_name = (char *)H5MM_xfree((void*)cls->cls_name);
+ cls->lib_name = (char *)H5MM_xfree((void*)cls->lib_name);
+ cls->lib_vers = (char *)H5MM_xfree((void*)cls->lib_vers);
+ cls = H5FL_FREE(H5E_cls_t, cls);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5E_free_class() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5Eregister_class
*
* Purpose: Registers an error class.
@@ -413,7 +443,7 @@ done:
static H5E_cls_t *
H5E_register_class(const char *cls_name, const char *lib_name, const char *version)
{
- H5E_cls_t *cls; /* Pointer to error class */
+ H5E_cls_t *cls = NULL; /* Pointer to error class */
H5E_cls_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5E_register_class)
@@ -424,7 +454,7 @@ H5E_register_class(const char *cls_name, const char *lib_name, const char *versi
HDassert(version);
/* Allocate space for new error class */
- if(NULL == (cls = H5FL_MALLOC(H5E_cls_t)))
+ if(NULL == (cls = H5FL_CALLOC(H5E_cls_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* Duplicate string information */
@@ -439,6 +469,10 @@ H5E_register_class(const char *cls_name, const char *lib_name, const char *versi
ret_value = cls;
done:
+ if(!ret_value)
+ if(cls && H5E_free_class(cls) < 0)
+ HDONE_ERROR(H5E_ERROR, H5E_CANTRELEASE, NULL, "unable to free error class")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5E_register_class() */
@@ -494,7 +528,9 @@ done:
static herr_t
H5E_unregister_class(H5E_cls_t *cls)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5E_unregister_class)
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5E_unregister_class)
/* Check arguments */
HDassert(cls);
@@ -504,15 +540,11 @@ H5E_unregister_class(H5E_cls_t *cls)
(void)H5I_search(H5I_ERROR_MSG, H5E_close_msg_cb, cls, FALSE);
/* Free error class structure */
- if(cls->cls_name)
- H5MM_xfree((void*)cls->cls_name);
- if(cls->lib_name)
- H5MM_xfree((void*)cls->lib_name);
- if(cls->lib_vers)
- H5MM_xfree((void*)cls->lib_vers);
- (void)H5FL_FREE(H5E_cls_t, cls);
+ if(H5E_free_class(cls) < 0)
+ HGOTO_ERROR(H5E_ERROR, H5E_CANTRELEASE, FAIL, "unable to free error class")
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5E_unregister_class() */
@@ -680,11 +712,10 @@ H5E_close_msg(H5E_msg_t *err)
/* Check arguments */
HDassert(err);
- if(err->msg)
- H5MM_xfree((void*)err->msg);
+ /* Release message */
+ err->msg = (char *)H5MM_xfree((void *)err->msg);
/* Don't free err->cls here */
-
- (void)H5FL_FREE(H5E_msg_t, err);
+ err = H5FL_FREE(H5E_msg_t, err);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5E_close_msg() */
@@ -749,7 +780,7 @@ done:
static H5E_msg_t *
H5E_create_msg(H5E_cls_t *cls, H5E_type_t msg_type, const char *msg_str)
{
- H5E_msg_t *msg; /* Pointer to new error message */
+ H5E_msg_t *msg = NULL; /* Pointer to new error message */
H5E_msg_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5E_create_msg)
@@ -773,6 +804,10 @@ H5E_create_msg(H5E_cls_t *cls, H5E_type_t msg_type, const char *msg_str)
ret_value = msg;
done:
+ if(!ret_value)
+ if(msg && H5E_close_msg(msg) < 0)
+ HDONE_ERROR(H5E_ERROR, H5E_CANTCLOSEOBJ, NULL, "unable to close error message")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5E_create_msg() */
diff --git a/src/H5Edeprec.c b/src/H5Edeprec.c
index 0997f3c..30f3ae9 100644
--- a/src/H5Edeprec.c
+++ b/src/H5Edeprec.c
@@ -122,10 +122,10 @@ char *
H5Eget_major(H5E_major_t maj)
{
H5E_msg_t *msg; /* Pointer to error message */
- ssize_t size = 0; /* Return value */
+ ssize_t size;
H5E_type_t type;
- char *msg_str;
- char *ret_value = NULL;
+ char *msg_str = NULL;
+ char *ret_value; /* Return value */
FUNC_ENTER_API_NOCLEAR(H5Eget_major, NULL)
@@ -133,22 +133,26 @@ H5Eget_major(H5E_major_t maj)
if(NULL == (msg = (H5E_msg_t *)H5I_object_verify(maj, H5I_ERROR_MSG)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a error message ID")
- /* Get the message's text */
+ /* Get the size & type of the message's text */
if((size = H5E_get_msg(msg, &type, NULL, (size_t)0)) < 0)
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text")
-
if(type != H5E_MAJOR)
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a major one")
- /* Don't know who is going to free it */
- msg_str = (char *)H5MM_malloc((size_t)(++size) * sizeof(char));
+ /* Application will free this */
+ size++;
+ msg_str = (char *)H5MM_malloc((size_t)size);
+ /* Get the text for the message */
if(H5E_get_msg(msg, NULL, msg_str, (size_t)size) < 0)
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text")
ret_value = msg_str;
done:
+ if(!ret_value)
+ msg_str = (char *)H5MM_xfree(msg_str);
+
FUNC_LEAVE_API(ret_value)
} /* end H5Eget_major() */
@@ -170,10 +174,10 @@ char *
H5Eget_minor(H5E_minor_t min)
{
H5E_msg_t *msg; /* Pointer to error message */
- ssize_t size = 0; /* Return value */
+ ssize_t size;
H5E_type_t type;
- char *msg_str;
- char *ret_value = NULL;
+ char *msg_str = NULL;
+ char *ret_value; /* Return value */
FUNC_ENTER_API_NOCLEAR(H5Eget_minor, NULL)
@@ -181,22 +185,26 @@ H5Eget_minor(H5E_minor_t min)
if(NULL == (msg = (H5E_msg_t *)H5I_object_verify(min, H5I_ERROR_MSG)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a error message ID")
- /* Get the message's text */
+ /* Get the size & type of the message's text */
if((size = H5E_get_msg(msg, &type, NULL, (size_t)0)) < 0)
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text")
-
if(type != H5E_MINOR)
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "Error message isn't a minor one")
- /* Don't know who is going to free it */
- msg_str = (char *)H5MM_malloc((size_t)(++size) * sizeof(char));
+ /* Application will free this */
+ size++;
+ msg_str = (char *)H5MM_malloc((size_t)size);
+ /* Get the text for the message */
if(H5E_get_msg(msg, NULL, msg_str, (size_t)size) < 0)
HGOTO_ERROR(H5E_ERROR, H5E_CANTGET, NULL, "can't get error message text")
ret_value = msg_str;
done:
+ if(!ret_value)
+ msg_str = (char *)H5MM_xfree(msg_str);
+
FUNC_LEAVE_API(ret_value)
} /* end H5Eget_minor() */
diff --git a/src/H5Eint.c b/src/H5Eint.c
index 3265fc7..7c40d76 100644
--- a/src/H5Eint.c
+++ b/src/H5Eint.c
@@ -225,8 +225,9 @@ H5E_walk1_cb(int n, H5E_error1_t *err_desc, void *client_data)
const char *maj_str = "No major description"; /* Major error description */
const char *min_str = "No minor description"; /* Minor error description */
unsigned have_desc = 1; /* Flag to indicate whether the error has a "real" description */
+ herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5E_walk1_cb)
+ FUNC_ENTER_NOAPI_NOINIT(H5E_walk1_cb)
/* Check arguments */
HDassert(err_desc);
@@ -240,7 +241,11 @@ H5E_walk1_cb(int n, H5E_error1_t *err_desc, void *client_data)
/* Get descriptions for the major and minor error numbers */
maj_ptr = (H5E_msg_t *)H5I_object_verify(err_desc->maj_num, H5I_ERROR_MSG);
min_ptr = (H5E_msg_t *)H5I_object_verify(err_desc->min_num, H5I_ERROR_MSG);
- HDassert(maj_ptr && min_ptr);
+
+ /* Check for bad pointer(s), but can't issue error, just leave */
+ if(!maj_ptr || !min_ptr)
+ HGOTO_DONE(FAIL)
+
if(maj_ptr->msg)
maj_str = maj_ptr->msg;
if(min_ptr->msg)
@@ -294,7 +299,8 @@ H5E_walk1_cb(int n, H5E_error1_t *err_desc, void *client_data)
fprintf(stream, "%*smajor: %s\n", (H5E_INDENT * 2), "", maj_str);
fprintf(stream, "%*sminor: %s\n", (H5E_INDENT * 2), "", min_str);
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5E_walk1_cb() */
#endif /* H5_NO_DEPRECATED_SYMBOLS */
@@ -341,8 +347,9 @@ H5E_walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data)
const char *maj_str = "No major description"; /* Major error description */
const char *min_str = "No minor description"; /* Minor error description */
unsigned have_desc = 1; /* Flag to indicate whether the error has a "real" description */
+ herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5E_walk2_cb)
+ FUNC_ENTER_NOAPI_NOINIT(H5E_walk2_cb)
/* Check arguments */
HDassert(err_desc);
@@ -356,7 +363,11 @@ H5E_walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data)
/* Get descriptions for the major and minor error numbers */
maj_ptr = (H5E_msg_t *)H5I_object_verify(err_desc->maj_num, H5I_ERROR_MSG);
min_ptr = (H5E_msg_t *)H5I_object_verify(err_desc->min_num, H5I_ERROR_MSG);
- HDassert(maj_ptr && min_ptr);
+
+ /* Check for bad pointer(s), but can't issue error, just leave */
+ if(!maj_ptr || !min_ptr)
+ HGOTO_DONE(FAIL)
+
if(maj_ptr->msg)
maj_str = maj_ptr->msg;
if(min_ptr->msg)
@@ -411,7 +422,8 @@ H5E_walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data)
fprintf(stream, "%*smajor: %s\n", (H5E_INDENT * 2), "", maj_str);
fprintf(stream, "%*sminor: %s\n", (H5E_INDENT * 2), "", min_str);
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5E_walk2_cb() */
diff --git a/src/H5FD.c b/src/H5FD.c
index 4c0da40..99f2e3c 100644
--- a/src/H5FD.c
+++ b/src/H5FD.c
@@ -730,8 +730,8 @@ done:
herr_t
H5FD_fapl_open(H5P_genplist_t *plist, hid_t driver_id, const void *driver_info)
{
- void *copied_driver_info; /* Temporary VFL driver info */
- herr_t ret_value=SUCCEED; /* Return value */
+ void *copied_driver_info = NULL; /* Temporary VFL driver info */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5FD_fapl_open, FAIL)
@@ -739,15 +739,20 @@ H5FD_fapl_open(H5P_genplist_t *plist, hid_t driver_id, const void *driver_info)
if(H5I_inc_ref(driver_id, FALSE) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTINC, FAIL, "unable to increment ref count on VFL driver")
if(H5FD_fapl_copy(driver_id, driver_info, &copied_driver_info) < 0)
- HGOTO_ERROR (H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy VFL driver info")
+ HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "can't copy VFL driver info")
/* Set the driver properties for the list */
if(H5P_set(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver ID")
+ HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set driver ID")
if(H5P_set(plist, H5F_ACS_FILE_DRV_INFO_NAME, &copied_driver_info) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set driver info")
+ HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set driver info")
+ copied_driver_info = NULL;
done:
+ if(ret_value < 0)
+ if(copied_driver_info && H5FD_fapl_close(driver_id, copied_driver_info) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEOBJ, FAIL, "can't close copy of driver info")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_fapl_open() */
@@ -847,24 +852,28 @@ done:
herr_t
H5FD_dxpl_open(H5P_genplist_t *plist, hid_t driver_id, const void *driver_info)
{
- void *copied_driver_info; /* Temporary VFL driver info */
- herr_t ret_value=SUCCEED; /* Return value */
+ void *copied_driver_info = NULL; /* Temporary VFL driver info */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5FD_dxpl_open, FAIL)
/* Increment the reference count on the driver and copy the driver info */
if(H5I_inc_ref(driver_id, FALSE) < 0)
- HGOTO_ERROR (H5E_DATASET, H5E_CANTINC, FAIL, "can't increment VFL driver ID")
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINC, FAIL, "can't increment VFL driver ID")
if(H5FD_dxpl_copy(driver_id, driver_info, &copied_driver_info) < 0)
- HGOTO_ERROR (H5E_DATASET, H5E_CANTCOPY, FAIL, "can't copy VFL driver")
+ HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "can't copy VFL driver")
/* Set the driver information for the new property list */
if(H5P_set(plist, H5D_XFER_VFL_ID_NAME, &driver_id) < 0)
- HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "can't set VFL driver ID")
+ HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set VFL driver ID")
if(H5P_set(plist, H5D_XFER_VFL_INFO_NAME, &copied_driver_info) < 0)
- HGOTO_ERROR (H5E_PLIST, H5E_CANTSET, FAIL, "can't set VFL driver info")
+ HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set VFL driver info")
done:
+ if(ret_value < 0)
+ if(copied_driver_info && H5FD_dxpl_close(driver_id, copied_driver_info) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEOBJ, FAIL, "can't close copy of driver info")
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_dxpl_open() */
@@ -1060,7 +1069,7 @@ H5FD_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
/* Get file access property list */
if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list")
/* Get the VFD to open the file with */
if(H5P_get(plist, H5F_ACS_FILE_DRV_ID_NAME, &driver_id) < 0)
diff --git a/src/H5FL.c b/src/H5FL.c
index c72491d..8ac442a 100644
--- a/src/H5FL.c
+++ b/src/H5FL.c
@@ -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) */
diff --git a/src/H5FS.c b/src/H5FS.c
index deb9378..8bc86ed 100644
--- a/src/H5FS.c
+++ b/src/H5FS.c
@@ -511,7 +511,7 @@ H5FS_t *
H5FS_new(size_t nclasses, const H5FS_section_class_t *classes[],
void *cls_init_udata)
{
- H5FS_t *fspace; /* Free space manager */
+ H5FS_t *fspace = NULL; /* Free space manager */
size_t u; /* Local index variable */
H5FS_t *ret_value; /* Return value */
@@ -559,6 +559,16 @@ H5FS_new(size_t nclasses, const H5FS_section_class_t *classes[],
ret_value = fspace;
done:
+ if(!ret_value)
+ if(fspace) {
+ /* Should probably call the class 'term' callback for all classes
+ * that have had their 'init' callback called... -QAK
+ */
+ if(fspace->sect_cls)
+ fspace->sect_cls = (H5FS_section_class_t *)H5FL_SEQ_FREE(H5FS_section_class_t, fspace->sect_cls);
+ fspace = H5FL_FREE(H5FS_t, fspace);
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* H5FS_new() */
diff --git a/src/H5FSsection.c b/src/H5FSsection.c
index 26ff7b9..9bdd99a 100644
--- a/src/H5FSsection.c
+++ b/src/H5FSsection.c
@@ -939,7 +939,8 @@ static herr_t
H5FS_sect_link_size(H5FS_sinfo_t *sinfo, const H5FS_section_class_t *cls,
H5FS_section_info_t *sect)
{
- H5FS_node_t *fspace_node = NULL; /* Pointer to free space node of the correct size */
+ H5FS_node_t *fspace_node = NULL; /* Pointer to free space node of the correct size */
+ hbool_t fspace_node_alloc = FALSE; /* Whether the free space node was allocated */
unsigned bin; /* Bin to put the free space section in */
herr_t ret_value = SUCCEED; /* Return value */
@@ -971,6 +972,7 @@ HDfprintf(stderr, "%s: sect->size = %Hu, sect->addr = %a\n", FUNC, sect->size, s
/* Allocate new free list size node */
if(NULL == (fspace_node = H5FL_MALLOC(H5FS_node_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for free space node")
+ fspace_node_alloc = TRUE;
/* Initialize the free list size node */
fspace_node->sect_size = sect->size;
@@ -981,6 +983,7 @@ HDfprintf(stderr, "%s: sect->size = %Hu, sect->addr = %a\n", FUNC, sect->size, s
/* Insert new free space size node into bin's list */
if(H5SL_insert(sinfo->bins[bin].bin_list, fspace_node, &fspace_node->sect_size) < 0)
HGOTO_ERROR(H5E_FSPACE, H5E_CANTINSERT, FAIL, "can't insert free space node into skip list")
+ fspace_node_alloc = FALSE; /* (owned by the bin skip list now, don't need to free on error) */
/* Increment number of section sizes */
sinfo->tot_size_count++;
@@ -1016,6 +1019,13 @@ HDfprintf(stderr, "%s: sinfo->bins[%u].sect_count = %Zu\n", FUNC, bin, sinfo->bi
HGOTO_ERROR(H5E_FSPACE, H5E_CANTINSERT, FAIL, "can't insert free space node into skip list")
done:
+ if(ret_value < 0)
+ if(fspace_node && fspace_node_alloc) {
+ if(fspace_node->sect_list && H5SL_close(fspace_node->sect_list) < 0)
+ HDONE_ERROR(H5E_FSPACE, H5E_CANTCLOSEOBJ, FAIL, "can't destroy size free space node's skip list")
+ fspace_node = H5FL_FREE(H5FS_node_t, fspace_node);
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* H5FS_sect_link_size() */
diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c
index ad8f8e1..db762cf 100644
--- a/src/H5Lexternal.c
+++ b/src/H5Lexternal.c
@@ -594,8 +594,8 @@ H5Lcreate_external(const char *file_name, const char *obj_name,
HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link")
done:
- if(norm_obj_name)
- H5MM_free(ext_link_buf);
+ H5MM_xfree(ext_link_buf);
+ H5MM_xfree(norm_obj_name);
FUNC_LEAVE_API(ret_value)
} /* end H5Lcreate_external() */
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index f86a743..bdcdc28 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -3531,6 +3531,7 @@ done:
herr_t
H5S_hyper_add_span_element(H5S_t *space, unsigned rank, hsize_t *coords)
{
+ H5S_hyper_span_info_t *head = NULL; /* Pointer to new head of span tree */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_add_span_element)
@@ -3541,8 +3542,6 @@ H5S_hyper_add_span_element(H5S_t *space, unsigned rank, hsize_t *coords)
/* Check if this is the first element in the selection */
if(NULL == space->select.sel_info.hslab) {
- H5S_hyper_span_info_t *head; /* Pointer to new head of span tree */
-
/* Allocate a span info node */
if(NULL == (head = H5FL_MALLOC(H5S_hyper_span_info_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span")
@@ -3574,7 +3573,7 @@ H5S_hyper_add_span_element(H5S_t *space, unsigned rank, hsize_t *coords)
space->select.num_elem = 1;
} /* end if */
else {
- if(H5S_hyper_add_span_element_helper(space->select.sel_info.hslab->span_lst,rank,coords) < 0)
+ if(H5S_hyper_add_span_element_helper(space->select.sel_info.hslab->span_lst, rank, coords) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span")
/* Increment # of elements in selection */
@@ -3582,6 +3581,10 @@ H5S_hyper_add_span_element(H5S_t *space, unsigned rank, hsize_t *coords)
} /* end else */
done:
+ if(ret_value < 0)
+ if(head)
+ H5S_hyper_free_span_info(head);
+
FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_hyper_add_span_element() */
@@ -5421,85 +5424,109 @@ static H5S_hyper_span_info_t *
H5S_hyper_make_spans (unsigned rank, const hsize_t *start, const hsize_t *stride,
const hsize_t *count, const hsize_t *block)
{
- H5S_hyper_span_info_t *down;/* Pointer to spans in next dimension down */
- H5S_hyper_span_t *span; /* New hyperslab span */
- H5S_hyper_span_t *last_span;/* Current position in hyperslab span list */
- H5S_hyper_span_t *head; /* Head of new hyperslab span list */
- hsize_t stride_iter; /* Iterator over the stride values */
- int i; /* Counters */
- unsigned u; /* Counters */
- H5S_hyper_span_info_t *ret_value;
+ H5S_hyper_span_info_t *down; /* Pointer to spans in next dimension down */
+ H5S_hyper_span_t *span; /* New hyperslab span */
+ H5S_hyper_span_t *last_span; /* Current position in hyperslab span list */
+ H5S_hyper_span_t *head; /* Head of new hyperslab span list */
+ hsize_t stride_iter; /* Iterator over the stride values */
+ int i; /* Counters */
+ unsigned u; /* Counters */
+ H5S_hyper_span_info_t *ret_value = NULL;
FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_make_spans);
/* Check args */
- assert (rank>0);
- assert (start);
- assert (stride);
- assert (count);
- assert (block);
+ HDassert(rank > 0);
+ HDassert(start);
+ HDassert(stride);
+ HDassert(count);
+ HDassert(block);
/* Start creating spans in fastest changing dimension */
- down=NULL;
- for(i=(rank-1); i>=0; i--) {
+ down = NULL;
+ for(i = (rank - 1); i >= 0; i--) {
/* Start a new list in this dimension */
- head=last_span=NULL;
+ head = NULL;
+ last_span = NULL;
- /* Generate all the spans segments for this dimension */
- for(u=0, stride_iter=0; u<count[i]; u++,stride_iter+=stride[i]) {
+ /* Generate all the span segments for this dimension */
+ for(u = 0, stride_iter = 0; u < count[i]; u++, stride_iter += stride[i]) {
/* Allocate a span node */
- if((span = H5FL_MALLOC(H5S_hyper_span_t))==NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate hyperslab span");
+ if(NULL == (span = H5FL_MALLOC(H5S_hyper_span_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate hyperslab span")
/* Set the span's basic information */
- span->low=start[i]+stride_iter;
- span->high=span->low+(block[i]-1);
- span->nelem=block[i];
- span->pstride=stride[i];
- span->next=NULL;
+ span->low = start[i] + stride_iter;
+ span->high = span->low + (block[i]-1);
+ span->nelem = block[i];
+ span->pstride = stride[i];
+ span->next = NULL;
/* Append to the list of spans in this dimension */
- if(head==NULL)
- head=span;
+ if(head == NULL)
+ head = span;
else
- last_span->next=span;
+ last_span->next = span;
/* Move current pointer */
- last_span=span;
+ last_span = span;
/* Set the information for the next dimension down's spans, if appropriate */
- if(down!=NULL) {
- span->down=down;
+ if(down != NULL) {
+ span->down = down;
down->count++; /* Increment reference count for shared span */
} /* end if */
else {
- span->down=NULL;
+ span->down = NULL;
} /* end else */
} /* end for */
/* Allocate a span info node */
- if((down = H5FL_MALLOC(H5S_hyper_span_info_t))==NULL)
+ if(NULL == (down = H5FL_MALLOC(H5S_hyper_span_info_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate hyperslab span");
/* Set the reference count */
- down->count=0;
+ down->count = 0;
/* Reset the scratch pad space */
- down->scratch=0;
+ down->scratch = 0;
/* Keep the pointer to the next dimension down's completed list */
- down->head=head;
+ down->head = head;
} /* end for */
/* Indicate that there is a pointer to this tree */
- down->count=1;
+ down->count = 1;
/* Success! Return the head of the list in the slowest changing dimension */
- ret_value=down;
+ ret_value = down;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ /* cleanup if error (ret_value will be NULL) */
+ if(!ret_value) {
+ if(head || down) {
+ if(head && down)
+ if(down->head != head)
+ down = NULL;
+
+ do {
+ if(down) {
+ head = down->head;
+ (void)H5FL_FREE(H5S_hyper_span_info_t, down);
+ } /* end if */
+ down = head->down;
+
+ while(head) {
+ last_span = head->next;
+ (void)H5FL_FREE(H5S_hyper_span_t, head);
+ head = last_span;
+ } /* end while */
+ } while(down);
+ } /* end if */
+ } /* end if */
+
+ FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_hyper_make_spans() */
@@ -6959,7 +6986,7 @@ H5Scombine_hyperslab(hid_t space_id, H5S_seloper_t op, const hsize_t start[],
/* Copy the first dataspace */
if (NULL == (new_space = H5S_copy (space, TRUE, TRUE)))
- HGOTO_ERROR (H5E_DATASPACE, H5E_CANTINIT, NULL, "unable to copy data space");
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, NULL, "unable to copy data space");
/* Go modify the selection in the new dataspace */
if (H5S_select_hyperslab(new_space, op, start, stride, count, block)<0)
@@ -6967,7 +6994,7 @@ H5Scombine_hyperslab(hid_t space_id, H5S_seloper_t op, const hsize_t start[],
/* Atomize */
if ((ret_value=H5I_register (H5I_DATASPACE, new_space, TRUE))<0)
- HGOTO_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace atom");
+ HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace atom");
done:
if (ret_value<0 && new_space)
@@ -7015,7 +7042,7 @@ H5S_combine_select (H5S_t *space1, H5S_seloper_t op, H5S_t *space2)
/* Copy the first dataspace */
if (NULL == (new_space = H5S_copy (space1, TRUE, TRUE)))
- HGOTO_ERROR (H5E_DATASPACE, H5E_CANTINIT, NULL, "unable to copy data space");
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, NULL, "unable to copy data space");
/* Free the current selection for the new dataspace */
if(H5S_SELECT_RELEASE(new_space)<0)
@@ -7095,7 +7122,7 @@ H5Scombine_select(hid_t space1_id, H5S_seloper_t op, hid_t space2_id)
/* Atomize */
if ((ret_value=H5I_register (H5I_DATASPACE, new_space, TRUE))<0)
- HGOTO_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace atom");
+ HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace atom");
done:
if (ret_value<0 && new_space)