summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-07-30 18:19:14 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-07-30 18:19:14 (GMT)
commit03ae0fecf0c60fc5ee722e27394c261a7a7345f7 (patch)
treec5de1bf156610c8987029ff07828d2d1cc415a50 /src
parentc173b3fee43d497f730fbd8f0399a8859c4929a9 (diff)
downloadhdf5-03ae0fecf0c60fc5ee722e27394c261a7a7345f7.zip
hdf5-03ae0fecf0c60fc5ee722e27394c261a7a7345f7.tar.gz
hdf5-03ae0fecf0c60fc5ee722e27394c261a7a7345f7.tar.bz2
[svn-r19157] Description:
Bring r19078 from Coverity branch to 1.8 branch (code doesn't exist on trunk): Purpose: Resolve Memory Leaks Description: Free saved ID structures in H5I interface when library shuts down. Tested on: Mac OS X/32 10.6.4 (amazon) w/debug & production (Too minor to require h5committest)
Diffstat (limited to 'src')
-rw-r--r--src/H5I.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/H5I.c b/src/H5I.c
index e39944f..1ecb9e6 100644
--- a/src/H5I.c
+++ b/src/H5I.c
@@ -698,6 +698,16 @@ H5I_clear_type(H5I_type_t type, hbool_t force, hbool_t app_ref)
} /* end for */
} /* end for */
+ /* Also free any ID structures being retained for potential re-use */
+ while(type_ptr->next_id_ptr) {
+ H5I_id_info_t *tmp_id_ptr; /* temp ptr to next atom */
+
+ tmp_id_ptr = type_ptr->next_id_ptr->next;
+ (void)H5FL_FREE(H5I_id_info_t, type_ptr->next_id_ptr);
+ type_ptr->next_id_ptr = tmp_id_ptr;
+ } /* end while */
+ type_ptr->free_count = 0;
+
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5I_clear_type() */
@@ -866,8 +876,7 @@ H5I_register(H5I_type_t type, const void *object, hbool_t app_ref)
HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "invalid type")
/* If there is an available ID structure, use it. */
- if (type_ptr->next_id_ptr) {
-
+ if(type_ptr->next_id_ptr) {
/* Use existing available ID struct */
id_ptr = type_ptr->next_id_ptr;
@@ -876,11 +885,10 @@ H5I_register(H5I_type_t type, const void *object, hbool_t app_ref)
/* Decrease count of available ID structures */
type_ptr->free_count--;
-
+ } /* end if */
/* If no available ID structure, then create a new id for use, and
* allocate a new struct to house it. */
- } else {
-
+ else {
/* Allocate new ID struct */
if(NULL == (id_ptr = H5FL_MALLOC(H5I_id_info_t)))
HGOTO_ERROR(H5E_ATOM, H5E_NOSPACE, FAIL, "memory allocation failed")
@@ -890,7 +898,6 @@ H5I_register(H5I_type_t type, const void *object, hbool_t app_ref)
/* Increment nextid value */
type_ptr->nextid++;
-
} /* end if */
/* Fill in remaining fields of ID struct */
@@ -1340,7 +1347,8 @@ H5I_remove(hid_t id)
/* Otherwise, just toss it. */
else
curr_id = H5FL_FREE(H5I_id_info_t, curr_id);
- } else {
+ } /* end if */
+ else {
/* couldn't find the ID in the proper place */
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "invalid ID")
}
@@ -1350,20 +1358,16 @@ H5I_remove(hid_t id)
/* If there are no more IDs of this type, then we can free all available
ID strutures, and reset starting typeid and wrapped status. */
- if (type_ptr->ids == 0) {
-
- while (type_ptr->next_id_ptr) {
-
+ if(type_ptr->ids == 0) {
+ while(type_ptr->next_id_ptr) {
tmp_id_ptr = type_ptr->next_id_ptr->next;
(void)H5FL_FREE(H5I_id_info_t, type_ptr->next_id_ptr);
type_ptr->next_id_ptr = tmp_id_ptr;
- type_ptr->free_count--;
-
} /* end while */
+ type_ptr->free_count = 0;
type_ptr->nextid = type_ptr->reserved;
type_ptr->wrapped = FALSE;
-
} /* end if */
done: