diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-23 07:00:00 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-23 07:00:00 (GMT) |
commit | bb25c85e794449d3bf59d8811e53288569161790 (patch) | |
tree | e6c37cf6f8bba9323540ddddb70300b43351d88f /src/H5E.c | |
parent | fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0 (diff) | |
download | hdf5-bb25c85e794449d3bf59d8811e53288569161790.zip hdf5-bb25c85e794449d3bf59d8811e53288569161790.tar.gz hdf5-bb25c85e794449d3bf59d8811e53288569161790.tar.bz2 |
[svn-r18159] Description:
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/H5E.c')
-rw-r--r-- | src/H5E.c | 67 |
1 files changed, 51 insertions, 16 deletions
@@ -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() */ |