diff options
author | jhendersonHDF <jhenderson@hdfgroup.org> | 2024-02-26 16:52:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-26 16:52:33 (GMT) |
commit | 221e4295788d3e5d2a8afe147c8127e8cf40732f (patch) | |
tree | 778206bdf7aa6464f487d859647bcc104c04a298 /src/H5Pfapl.c | |
parent | 560e80c0ad8494a2e070aafde9cbcff11de99219 (diff) | |
download | hdf5-221e4295788d3e5d2a8afe147c8127e8cf40732f.zip hdf5-221e4295788d3e5d2a8afe147c8127e8cf40732f.tar.gz hdf5-221e4295788d3e5d2a8afe147c8127e8cf40732f.tar.bz2 |
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.
Diffstat (limited to 'src/H5Pfapl.c')
-rw-r--r-- | src/H5Pfapl.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index e9496bf..6c2ef47 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -3159,9 +3159,10 @@ done: herr_t H5Pset_file_image_callbacks(hid_t fapl_id, H5FD_file_image_callbacks_t *callbacks_ptr) { - H5P_genplist_t *fapl; /* Property list pointer */ - H5FD_file_image_info_t info; /* File image info */ - herr_t ret_value = SUCCEED; /* Return value */ + H5P_genplist_t *fapl; /* Property list pointer */ + H5FD_file_image_info_t info; /* File image info */ + bool copied_udata = false; /* Whether udata structure was copied */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE2("e", "i*DI", fapl_id, callbacks_ptr); @@ -3209,11 +3210,18 @@ H5Pset_file_image_callbacks(hid_t fapl_id, H5FD_file_image_callbacks_t *callback HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't copy the supplied udata"); } /* end if */ + copied_udata = true; + /* Set values */ if (H5P_poke(fapl, H5F_ACS_FILE_IMAGE_INFO_NAME, &info) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set file image info"); done: + if (ret_value < 0) { + if (copied_udata && (callbacks_ptr->udata_free(info.callbacks.udata) < 0)) + HDONE_ERROR(H5E_RESOURCE, H5E_CANTFREE, FAIL, "udata_free callback failed"); + } + FUNC_LEAVE_API(ret_value) } /* end H5Pset_file_image_callbacks() */ |