diff options
author | Larry Knox <lrknox@hdfgroup.org> | 2024-03-05 14:52:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-05 14:52:09 (GMT) |
commit | 7741170bdd225da130f3ab98c454c118b5511b14 (patch) | |
tree | 35e631c884f16cf1251523c703b25df5cb178541 /hl/src | |
parent | c44e0e35ed584d4efe67bdf1dafe25a793085e0f (diff) | |
download | hdf5-7741170bdd225da130f3ab98c454c118b5511b14.zip hdf5-7741170bdd225da130f3ab98c454c118b5511b14.tar.gz hdf5-7741170bdd225da130f3ab98c454c118b5511b14.tar.bz2 |
Sync develop branch changes since 2/16 to hdf5_1_14 branch (#4058)
* Remove oneapi return value warning. (#4028)
* Replaced last sprintf with snprintf (#4007)
* Replaced last sprintf with snprintf
To have the size of the buffer, it was required to change a function signature, and change all users of it.
In most cases, determining the buffer size wasn't trivial and so SIZE_MAX is passed. But at least this improves the infrastructure. Someone can later figure out the correct sizes.
* Test vlen sequence IO in API tests (#4027)
* Check argument for CMake REGEX FCMangle.h. (#4029)
* Replace deprecated Fortran 'include mpif.h' with 'USE mpi' (#4031)
With MPI 4.1 the use of the mpif.h include file has been deprecated. Codes
should transition to USE mpi or USE mpi_f08.
Signed-off-by: Christoph Niethammer <niethammer@hlrs.de>
* Fix H5F_get_access_plist to copy file locking settings (#4030)
H5F_get_access_plist previously did not copy over the file locking settings
from a file into the new File Access Property List that it creates. This would
make it difficult to match the file locking settings between an external file
and its parent file.
* Fix missing NOT from if check in HL folder (#4036)
* Fix the datatype passed to H5*exists_async APIs in tests. (#4033)
Add a new testing function to verify C_BOOL values.
* Add deb and rpm binaries to snapshots (#4035)
* Update and Add general INSTALL (#4016)
* Improve performance of flushing single objects (#4017)
Improve performance of flushing a single object, and remove metadata
cache flush markers
* Fix memory leak in H5LTopen_file_image when H5LT_FILE_IMAGE_DONT_COPY flag is used (#4021)
When the H5LT_FILE_IMAGE_DONT_COPY flag is passed to H5LTopen_file_image, the internally-allocated
udata structure gets leaked as the core file driver doesn't have a way to determine when or if it
needs to call the 'udata_free' callback. This has been fixed by freeing the udata structure when
the 'image_free' callback gets made during file close, where the file is holding the last reference
to the udata structure.
* Fix allocating too much memory in dset API test (#4041)
* Don't try to load general-19 warnings file for icc (#4042)
The Autools Classic Intel compiler configuration attempts to load a file
named `general-19` from the intel-warnings/classic directory, which does
not exist.
This removes the attempted load of the file.
* Remove unused AIX cross-compile cache overrides (#4043)
The ibm-aix Autotools config file had some unmaintained and unnecessary
Autoconf cache overrides. These have been removed.
* Consolidate Autotools linux files (#4044)
There are many architecture-specific linux files in the config
directory, all of which simply redirect to linux-gnulibc1.
This change renames linux-gnulibc1 to linux-gnu and deletes the more
specific files.
* Remove check for gettimeofday + tz in CMake (#4045)
This is not used in the library
* Remove limitations on preset generators (#4051)
* Fix issue with FAPL file locking setting inheriting test (#4053)
Fixes an issue where the HDF5_USE_FILE_LOCKING environment variable being
set can interfere with the file locking setting that the test expects to
be returned.
* Bump the github-actions group with 2 updates (#4054)
Bumps the github-actions group with 2 updates: [actions/download-artifact](https://github.com/actions/download-artifact) and [github/codeql-action](https://github.com/github/codeql-action).
* Fix VOL-compatibility issues in External Link API test (#4039)
Fix link API tests with incorrect filename
* Add upddated cmake tools from source location (#4040)
* Add options to allow tools type selection and naming (#4046)
* Improve error messages when tools attempt to use non-enabled S3 and HDFS VFDs. (#4047)
* Correct several 1.15/1.15.0 references to 1.14/1.14.4.
* Ignore HDF5Examples/CMakeUserPresets.json
Diffstat (limited to 'hl/src')
-rw-r--r-- | hl/src/H5LT.c | 85 |
1 files changed, 67 insertions, 18 deletions
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c index 6bd1337..099356f 100644 --- a/hl/src/H5LT.c +++ b/hl/src/H5LT.c @@ -286,14 +286,33 @@ image_realloc(void *ptr, size_t size, H5FD_file_image_op_t file_image_op, void * goto out; if (file_image_op == H5FD_FILE_IMAGE_OP_FILE_RESIZE) { + void *tmp_realloc; + if (udata->vfd_image_ptr != ptr) goto out; if (udata->vfd_ref_count != 1) goto out; - if (NULL == (udata->vfd_image_ptr = realloc(ptr, size))) + /* Make sure all the udata structure image pointers + * match each other before we update them + */ + assert(udata->vfd_image_ptr == udata->app_image_ptr); + assert(udata->vfd_image_ptr == udata->fapl_image_ptr); + + tmp_realloc = realloc(ptr, size); + if (tmp_realloc) { + udata->vfd_image_ptr = tmp_realloc; + udata->app_image_ptr = udata->vfd_image_ptr; + udata->fapl_image_ptr = udata->vfd_image_ptr; + } + else { + free(ptr); + udata->vfd_image_ptr = NULL; + udata->app_image_ptr = NULL; + udata->fapl_image_ptr = NULL; goto out; + } udata->vfd_image_size = size; return_value = udata->vfd_image_ptr; @@ -359,11 +378,20 @@ image_free(void *ptr, H5FD_file_image_op_t file_image_op, void *_udata) * references */ if (udata->fapl_ref_count == 0 && udata->vfd_ref_count == 0 && !(udata->flags & H5LT_FILE_IMAGE_DONT_RELEASE)) { + /* Make sure we aren't going to leak memory elsewhere */ + assert(udata->app_image_ptr == udata->vfd_image_ptr || udata->app_image_ptr == NULL); + assert(udata->fapl_image_ptr == udata->vfd_image_ptr || udata->fapl_image_ptr == NULL); + free(udata->vfd_image_ptr); udata->app_image_ptr = NULL; udata->fapl_image_ptr = NULL; udata->vfd_image_ptr = NULL; - } /* end if */ + } + + /* release reference to udata structure */ + if (udata_free(udata) < 0) + goto out; + break; /* added unused labels to keep the compiler quite */ @@ -437,9 +465,15 @@ udata_free(void *_udata) udata->ref_count--; - /* checks that there are no references outstanding before deallocating udata */ - if (udata->ref_count == 0 && udata->fapl_ref_count == 0 && udata->vfd_ref_count == 0) + if (udata->ref_count == 0) { + /* There should not be any outstanding references + * to the udata structure at this point. + */ + assert(udata->fapl_ref_count == 0); + assert(udata->vfd_ref_count == 0); + free(udata); + } return (SUCCEED); @@ -728,13 +762,13 @@ out: hid_t H5LTopen_file_image(void *buf_ptr, size_t buf_size, unsigned flags) { - hid_t fapl = -1, file_id = -1; /* HDF5 identifiers */ - unsigned file_open_flags; /* Flags for image open */ - char file_name[64]; /* Filename buffer */ - size_t alloc_incr; /* Buffer allocation increment */ - size_t min_incr = 65536; /* Minimum buffer increment */ - double buf_prcnt = 0.1; /* Percentage of buffer size to set - as increment */ + H5LT_file_image_ud_t *udata = NULL; /* Pointer to udata structure */ + hid_t fapl = -1, file_id = -1; /* HDF5 identifiers */ + unsigned file_open_flags; /* Flags for image open */ + char file_name[64]; /* Filename buffer */ + size_t alloc_incr; /* Buffer allocation increment */ + size_t min_incr = 65536; /* Minimum buffer increment */ + double buf_prcnt = 0.1; /* Percentage of buffer size to set as increment */ static long file_name_counter; H5FD_file_image_callbacks_t callbacks = {&image_malloc, &image_memcpy, &image_realloc, &image_free, &udata_copy, &udata_free, (void *)NULL}; @@ -765,13 +799,11 @@ H5LTopen_file_image(void *buf_ptr, size_t buf_size, unsigned flags) /* Set callbacks for file image ops ONLY if the file image is NOT copied */ if (flags & H5LT_FILE_IMAGE_DONT_COPY) { - H5LT_file_image_ud_t *udata; /* Pointer to udata structure */ - /* Allocate buffer to communicate user data to callbacks */ if (NULL == (udata = (H5LT_file_image_ud_t *)malloc(sizeof(H5LT_file_image_ud_t)))) goto out; - /* Initialize udata with info about app buffer containing file image and flags */ + /* Initialize udata with info about app buffer containing file image and flags */ udata->app_image_ptr = buf_ptr; udata->app_image_size = buf_size; udata->fapl_image_ptr = NULL; @@ -781,17 +813,32 @@ H5LTopen_file_image(void *buf_ptr, size_t buf_size, unsigned flags) udata->vfd_image_size = 0; udata->vfd_ref_count = 0; udata->flags = flags; - udata->ref_count = 1; /* corresponding to the first FAPL */ + + /* + * Initialize the udata structure with a reference count of 1. At + * first, nothing holds this reference to the udata structure. The + * call to H5Pset_file_image_callbacks below will associate the + * udata structure with the FAPL, incrementing the structure's + * reference count and causing the FAPL to hold one of the two + * references to the structure in preparation for transfer of + * ownership to the file driver. Once the file has been opened with + * this FAPL and the FAPL is closed, the reference held by the FAPL + * is released and ownership is transferred to the file driver, which + * will then hold the remaining reference to the udata structure. + * The udata structure will then be freed when the file driver calls + * the image_free callback and releases its reference to the structure. + */ + udata->ref_count = 1; /* copy address of udata into callbacks */ callbacks.udata = (void *)udata; /* Set file image callbacks */ if (H5Pset_file_image_callbacks(fapl, &callbacks) < 0) { - free(udata); + udata_free(udata); goto out; - } /* end if */ - } /* end if */ + } + } /* end if */ /* Assign file image in user buffer to FAPL */ if (H5Pset_file_image(fapl, buf_ptr, buf_size) < 0) @@ -821,8 +868,10 @@ out: H5E_BEGIN_TRY { H5Pclose(fapl); + H5Fclose(file_id); } H5E_END_TRY + return -1; } /* end H5LTopen_file_image() */ |