summaryrefslogtreecommitdiffstats
path: root/src/H5Fmount.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Fmount.c')
-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;