summaryrefslogtreecommitdiffstats
path: root/src/H5Fmount.c
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2008-11-17 19:00:02 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2008-11-17 19:00:02 (GMT)
commita6493ad0c094fdfbc3068502a9b7a39fc3f450cc (patch)
tree261eba48742692ba26d763ab58c9088b9ecf8af2 /src/H5Fmount.c
parent0426a9ff069074e06a1f3a8a53319b2abc026370 (diff)
downloadhdf5-a6493ad0c094fdfbc3068502a9b7a39fc3f450cc.zip
hdf5-a6493ad0c094fdfbc3068502a9b7a39fc3f450cc.tar.gz
hdf5-a6493ad0c094fdfbc3068502a9b7a39fc3f450cc.tar.bz2
[svn-r16083] 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. (Port to 1.8) Tested: kagiso linew smirom (h5committest)
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;