Updated the 'const memory free' changes based on PR feedback.

This commit is contained in:
Dana Robinson 2020-01-30 16:31:11 -08:00
parent 9da387342e
commit 88b4c915e8
9 changed files with 27 additions and 45 deletions

View File

@ -1034,7 +1034,6 @@ H5CX_restore_state(const H5CX_state_t *api_state)
*
*-------------------------------------------------------------------------
*/
H5_GCC_DIAG_OFF(cast-qual)
herr_t
H5CX_free_state(H5CX_state_t *api_state)
{
@ -1072,9 +1071,9 @@ H5CX_free_state(H5CX_state_t *api_state)
/* Release the VOL connector property, if it was set */
if(api_state->vol_connector_prop.connector_id) {
/* Clean up any VOL connector info, ignoring const-ness of connector info */
/* Clean up any VOL connector info */
if(api_state->vol_connector_prop.connector_info)
if(H5VL_free_connector_info(api_state->vol_connector_prop.connector_id, (void *)api_state->vol_connector_prop.connector_info) < 0)
if(H5VL_free_connector_info(api_state->vol_connector_prop.connector_id, api_state->vol_connector_prop.connector_info) < 0)
HGOTO_ERROR(H5E_CONTEXT, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object")
/* Decrement connector ID */
if(H5I_dec_ref(api_state->vol_connector_prop.connector_id) < 0)
@ -1087,7 +1086,6 @@ H5CX_free_state(H5CX_state_t *api_state)
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5CX_free_state() */
H5_GCC_DIAG_ON(cast-qual)
/*-------------------------------------------------------------------------

View File

@ -202,7 +202,7 @@ H5FD__free_cls(H5FD_class_t *cls)
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_free_cls() */
} /* end H5FD__free_cls() */
/*-------------------------------------------------------------------------
@ -566,17 +566,16 @@ done:
/*-------------------------------------------------------------------------
* Function: H5FD_fapl_close
* Function: H5FD_free_driver_info
*
* Purpose: Closes a driver for a dataset transfer property list
* Purpose: Frees a driver's info
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
H5_GCC_DIAG_OFF(cast-qual)
herr_t
H5FD_fapl_close(hid_t driver_id, const void *driver_info)
H5FD_free_driver_info(hid_t driver_id, const void *driver_info)
{
herr_t ret_value = SUCCEED; /* Return value */
@ -592,8 +591,9 @@ H5FD_fapl_close(hid_t driver_id, const void *driver_info)
/* Allow driver to free info or do it ourselves */
if(driver_info) {
if(driver->fapl_free) {
/* Free the const pointer (why we turn off the diagnostic) */
if((driver->fapl_free)((void *)driver_info) < 0)
/* Free the const pointer */
/* Cast through uintptr_t to de-const memory */
if((driver->fapl_free)((void *)(uintptr_t)driver_info) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "driver free request failed")
}
else
@ -603,8 +603,7 @@ H5FD_fapl_close(hid_t driver_id, const void *driver_info)
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_fapl_close() */
H5_GCC_DIAG_ON(cast-qual)
} /* end H5FD_free_driver_info() */
/*-------------------------------------------------------------------------

View File

@ -115,7 +115,7 @@ H5_DLL hsize_t H5FD_sb_size(H5FD_t *file);
H5_DLL herr_t H5FD_sb_encode(H5FD_t *file, char *name/*out*/, uint8_t *buf);
H5_DLL herr_t H5FD_sb_load(H5FD_t *file, const char *name, const uint8_t *buf);
H5_DLL void *H5FD_fapl_get(H5FD_t *file);
H5_DLL herr_t H5FD_fapl_close(hid_t driver_id, const void *fapl);
H5_DLL herr_t H5FD_free_driver_info(hid_t driver_id, const void *driver_info);
H5_DLL hid_t H5FD_register(const void *cls, size_t size, hbool_t app_ref);
H5_DLL H5FD_t *H5FD_open(const char *name, unsigned flags, hid_t fapl_id,
haddr_t maxaddr);

View File

@ -273,7 +273,7 @@ H5F_get_access_plist(H5F_t *f, hbool_t app_ref)
done:
/* Release the copy of the driver info, if it was set up */
if(driver_prop_copied && H5FD_fapl_close(driver_prop.driver_id, driver_prop.driver_info) < 0)
if(driver_prop_copied && H5FD_free_driver_info(driver_prop.driver_id, driver_prop.driver_info) < 0)
HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEOBJ, H5I_INVALID_HID, "can't close copy of driver info")
FUNC_LEAVE_NOAPI(ret_value)

View File

@ -577,18 +577,17 @@ H5MM_xfree(void *mem)
*
*-------------------------------------------------------------------------
*/
H5_GCC_DIAG_OFF(cast-qual)
void *
H5MM_xfree_const(const void *mem)
{
/* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
FUNC_ENTER_NOAPI_NOINIT_NOERR
H5MM_xfree((void *)mem);
/* Cast through uintptr_t to de-const memory */
H5MM_xfree((void *)(uintptr_t)mem);
FUNC_LEAVE_NOAPI(NULL)
} /* end H5MM_xfree_const() */
H5_GCC_DIAG_ON(cast-qual)
/*-------------------------------------------------------------------------

View File

@ -1146,7 +1146,6 @@ done:
*
*-------------------------------------------------------------------------
*/
H5_GCC_DIAG_OFF(cast-qual)
static herr_t
H5P__file_driver_free(void *value)
{
@ -1159,22 +1158,11 @@ H5P__file_driver_free(void *value)
/* Copy the driver & info, if there is one */
if(info->driver_id > 0) {
if(info->driver_info) {
H5FD_class_t *driver; /* Pointer to driver */
/* Retrieve the driver for the ID */
if(NULL == (driver = (H5FD_class_t *)H5I_object(info->driver_id)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a driver ID")
/* Allow driver to free info or do it ourselves */
if(driver->fapl_free) {
/* Free the const pointer (why we turn off the diagnostic) */
if((driver->fapl_free)((void *)info->driver_info) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTFREE, FAIL, "driver info free request failed")
}
else
H5MM_xfree_const(info->driver_info);
}
/* Free the driver info, if it exists */
if(info->driver_info)
if(H5FD_free_driver_info(info->driver_id, info->driver_info) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTFREE, FAIL, "driver info free request failed")
/* Decrement reference count for driver */
if(H5I_dec_ref(info->driver_id) < 0)
@ -1185,7 +1173,6 @@ H5P__file_driver_free(void *value)
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5P__file_driver_free() */
H5_GCC_DIAG_ON(cast-qual)
/*-------------------------------------------------------------------------

View File

@ -525,7 +525,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
H5VL_free_connector_info(hid_t connector_id, void *info)
H5VL_free_connector_info(hid_t connector_id, const void *info)
{
H5VL_class_t *cls; /* VOL connector's class struct */
herr_t ret_value = SUCCEED; /* Return value */
@ -543,12 +543,13 @@ H5VL_free_connector_info(hid_t connector_id, void *info)
if(info) {
/* Allow the connector to free info or do it ourselves */
if(cls->info_cls.free) {
if((cls->info_cls.free)(info) < 0)
/* Cast through uintptr_t to de-const memory */
if((cls->info_cls.free)((void *)(uintptr_t)info) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "connector info free request failed")
} /* end if */
}
else
H5MM_xfree(info);
} /* end if */
H5MM_xfree_const(info);
}
done:
FUNC_LEAVE_NOAPI(ret_value)

View File

@ -670,7 +670,6 @@ done:
*
*-------------------------------------------------------------------------
*/
H5_GCC_DIAG_OFF(cast-qual)
herr_t
H5VL_conn_free(const H5VL_connector_prop_t *connector_prop)
{
@ -682,8 +681,8 @@ H5VL_conn_free(const H5VL_connector_prop_t *connector_prop)
/* Free the connector info (if it exists) and decrement the ID */
if(connector_prop->connector_id > 0) {
if(connector_prop->connector_info)
/* Free the connector info, ignoring the const */
if(H5VL_free_connector_info(connector_prop->connector_id, (void *)connector_prop->connector_info) < 0)
/* Free the connector info */
if(H5VL_free_connector_info(connector_prop->connector_id, connector_prop->connector_info) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object")
/* Decrement reference count for connector ID */
@ -695,7 +694,6 @@ H5VL_conn_free(const H5VL_connector_prop_t *connector_prop)
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_conn_free() */
H5_GCC_DIAG_ON(cast-qual)
/*-------------------------------------------------------------------------

View File

@ -128,7 +128,7 @@ H5_DLL int H5VL_copy_connector_info(const H5VL_class_t *connector, void **dst_in
const void *src_info);
H5_DLL herr_t H5VL_cmp_connector_info(const H5VL_class_t *connector, int *cmp_value,
const void *info1, const void *info2);
H5_DLL herr_t H5VL_free_connector_info(hid_t connector_id, void *info);
H5_DLL herr_t H5VL_free_connector_info(hid_t connector_id, const void *info);
/* Attribute functions */
H5_DLL void *H5VL_attr_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req);