diff options
Diffstat (limited to 'src/H5Fint.c')
-rw-r--r-- | src/H5Fint.c | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/H5Fint.c b/src/H5Fint.c index 4da382b..f4e6550 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -568,12 +568,12 @@ H5F_new(H5F_file_t *shared, unsigned flags, hid_t fcpl_id, hid_t fapl_id, H5FD_t FUNC_ENTER_NOAPI_NOINIT if(NULL == (f = H5FL_CALLOC(H5F_t))) - HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate top file structure") + HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate top file structure") f->file_id = -1; if(shared) { HDassert(lf == NULL); - f->shared = shared; + f->shared = shared; } /* end if */ else { H5P_genplist_t *plist; /* Property list */ @@ -586,18 +586,18 @@ H5F_new(H5F_file_t *shared, unsigned flags, hid_t fcpl_id, hid_t fapl_id, H5FD_t HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate shared file structure") f->shared->flags = flags; - f->shared->sohm_addr = HADDR_UNDEF; - f->shared->sohm_vers = HDF5_SHAREDHEADER_VERSION; + f->shared->sohm_addr = HADDR_UNDEF; + f->shared->sohm_vers = HDF5_SHAREDHEADER_VERSION; for(u = 0; u < NELMTS(f->shared->fs_addr); u++) f->shared->fs_addr[u] = HADDR_UNDEF; - f->shared->accum.loc = HADDR_UNDEF; + f->shared->accum.loc = HADDR_UNDEF; f->shared->lf = lf; - /* - * Copy the file creation and file access property lists into the - * new file handle. We do this early because some values might need - * to change as the file is being opened. - */ + /* + * Copy the file creation and file access property lists into the + * new file handle. We do this early because some values might need + * to change as the file is being opened. + */ if(NULL == (plist = (H5P_genplist_t *)H5I_object(fcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not property list") f->shared->fcpl_id = H5P_copy_plist(plist, FALSE); @@ -636,9 +636,9 @@ H5F_new(H5F_file_t *shared, unsigned flags, hid_t fcpl_id, hid_t fapl_id, H5FD_t HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get sieve buffer size") if(H5P_get(plist, H5F_ACS_LATEST_FORMAT_NAME, &latest_format) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get 'latest format' flag") - /* For latest format, activate all latest version support */ - if(latest_format) - f->shared->latest_flags |= H5F_LATEST_ALL_FLAGS; + /* For latest format, activate all latest version support */ + if(latest_format) + f->shared->latest_flags |= H5F_LATEST_ALL_FLAGS; if(H5P_get(plist, H5F_ACS_META_BLOCK_SIZE_NAME, &(f->shared->meta_aggr.alloc_size)) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get metadata cache size") f->shared->meta_aggr.feature_flag = H5FD_FEAT_AGGREGATE_METADATA; @@ -679,21 +679,21 @@ H5F_new(H5F_file_t *shared, unsigned flags, hid_t fcpl_id, hid_t fapl_id, H5FD_t */ f->shared->use_tmp_space = !H5F_HAS_FEATURE(f, H5FD_FEAT_HAS_MPI); - /* - * Create a metadata cache with the specified number of elements. - * The cache might be created with a different number of elements and - * the access property list should be updated to reflect that. - */ - if(H5AC_create(f, &(f->shared->mdc_initCacheCfg)) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to create metadata cache") + /* + * Create a metadata cache with the specified number of elements. + * The cache might be created with a different number of elements and + * the access property list should be updated to reflect that. + */ + if(H5AC_create(f, &(f->shared->mdc_initCacheCfg)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to create metadata cache") /* Create the file's "open object" information */ if(H5FO_create(f) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to create open object data structure") + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to create open object data structure") /* Add new "shared" struct to list of open files */ if(H5F_sfile_add(f->shared) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to append to list of open files") + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "unable to append to list of open files") } /* end else */ f->shared->nrefs++; @@ -707,7 +707,7 @@ H5F_new(H5F_file_t *shared, unsigned flags, hid_t fcpl_id, hid_t fapl_id, H5FD_t done: if(!ret_value && f) { - if(!shared) { + if(!shared) { /* Attempt to clean up some of the shared file structures */ if(f->shared->efc) if(H5F_efc_destroy(f->shared->efc) < 0) @@ -718,7 +718,7 @@ done: f->shared = H5FL_FREE(H5F_file_t, f->shared); } /* end if */ - f = H5FL_FREE(H5F_t, f); + f = H5FL_FREE(H5F_t, f); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) @@ -1544,6 +1544,10 @@ H5F_build_actual_name(const H5F_t *f, const H5P_genplist_t *fapl, const char *na char **actual_name/*out*/) { hid_t new_fapl_id = -1; /* ID for duplicated FAPL */ +#ifdef H5_HAVE_SYMLINK + /* This has to be declared here to avoid unfreed resources on errors */ + char *realname = NULL; /* Fully resolved path name of file */ +#endif /* H5_HAVE_SYMLINK */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -1575,9 +1579,12 @@ H5F_build_actual_name(const H5F_t *f, const H5P_genplist_t *fapl, const char *na int *fd; /* POSIX I/O file descriptor */ h5_stat_t st; /* Stat info from stat() call */ h5_stat_t fst; /* Stat info from fstat() call */ - char realname[PATH_MAX]; /* Fully resolved path name of file */ hbool_t want_posix_fd; /* Flag for retrieving file descriptor from VFD */ + /* Allocate realname buffer */ + if(NULL == (realname = (char *)H5MM_calloc((size_t)PATH_MAX * sizeof(char)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + /* Perform a sanity check that the file or link wasn't switched * between when we opened it and when we called lstat(). This is * according to the security best practices for lstat() documented @@ -1634,6 +1641,10 @@ done: if(new_fapl_id > 0) if(H5I_dec_app_ref(new_fapl_id) < 0) HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEOBJ, FAIL, "can't close duplicated FAPL") +#ifdef H5_HAVE_SYMLINK + if(realname) + realname = (char *)H5MM_xfree(realname); +#endif /* H5_HAVE_SYMLINK */ FUNC_LEAVE_NOAPI(ret_value) } /* H5F_build_actual_name() */ |