summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2008-11-17 18:48:37 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2008-11-17 18:48:37 (GMT)
commite86e9f49f65d15a120d5933b8be5c9fb118aa4ab (patch)
treec0180b36cf088b273f3486d7c282206a5fedb2a6 /src
parent2d445f880dc729d6815bdf56b2e8808382c80996 (diff)
downloadhdf5-e86e9f49f65d15a120d5933b8be5c9fb118aa4ab.zip
hdf5-e86e9f49f65d15a120d5933b8be5c9fb118aa4ab.tar.gz
hdf5-e86e9f49f65d15a120d5933b8be5c9fb118aa4ab.tar.bz2
[svn-r16082] Purpose: Fix a problem in the file unmounting code
Description: Fixes a problem in H5F_close_mounts where it wouldn't correctly reshape the "child" array when unmounting files. Test added for this case. Also fixed a potential bug in H5F_unmount where that routine reshapes the child array. Tested: kagiso linew smirom (h5committest)
Diffstat (limited to 'src')
-rw-r--r--src/H5Fmount.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/H5Fmount.c b/src/H5Fmount.c
index 0c31be6..a428cd6 100644
--- a/src/H5Fmount.c
+++ b/src/H5Fmount.c
@@ -79,8 +79,10 @@ H5F_close_mounts(H5F_t *f)
HDassert(f);
- /* Unmount all child files */
- for (u = 0; u < f->shared->mtab.nmounts; u++) {
+ /* Unmount all child files. Loop backwards to avoid having to adjust u when
+ * a file is unmounted. Note that we rely on unsigned u "wrapping around"
+ * to terminate the loop. */
+ for (u = f->shared->mtab.nmounts - 1; u < f->shared->mtab.nmounts; u--) {
/* Only unmount children mounted to this top level file structure */
if(f->shared->mtab.child[u].file->parent == f) {
/* Detach the child file from the parent file */
@@ -93,10 +95,16 @@ H5F_close_mounts(H5F_t *f)
/* Close the child file */
if(H5F_try_close(f->shared->mtab.child[u].file) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close child file")
+
+ /* Eliminate the mount point from the table */
+ HDmemmove(f->shared->mtab.child + u, f->shared->mtab.child + u + 1,
+ (f->shared->mtab.nmounts - u - 1) * sizeof(f->shared->mtab.child[0]));
+ f->shared->mtab.nmounts--;
+ f->nmounts--;
}
} /* end if */
- f->shared->mtab.nmounts -= f->nmounts;
- f->nmounts = 0;
+
+ HDassert(f->nmounts == 0);
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -390,7 +398,7 @@ H5F_unmount(H5G_loc_t *loc, const char *name, hid_t dxpl_id)
/* Eliminate the mount point from the table */
HDmemmove(parent->shared->mtab.child + child_idx, parent->shared->mtab.child + child_idx + 1,
- (parent->shared->mtab.nmounts-child_idx) * sizeof(parent->shared->mtab.child[0]));
+ (parent->shared->mtab.nmounts - child_idx - 1) * sizeof(parent->shared->mtab.child[0]));
parent->shared->mtab.nmounts -= 1;
parent->nmounts -= 1;