Skip to content

Fix memory leak when decoding a property list with a virtual dataset layout #5694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 52 additions & 12 deletions src/H5Pdcpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,22 +630,62 @@ H5P__dcrt_layout_dec(const void **_pp, void *value)

/* Decode each entry */
for (u = 0; u < (size_t)nentries; u++) {
/* Source file name */
H5O_storage_virtual_ent_t
*tmp_ent; /* Temporary VDS entry pointer, for hash table lookups */

/* Check for source file name in hash table */
tmp_ent = NULL;
tmp_size = strlen((const char *)*pp) + 1;
if (NULL ==
(tmp_layout.storage.u.virt.list[u].source_file_name = (char *)H5MM_malloc(tmp_size)))
HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL,
"unable to allocate memory for source file name");
H5MM_memcpy(tmp_layout.storage.u.virt.list[u].source_file_name, *pp, tmp_size);
if (tmp_layout.storage.u.virt.list_nused > 0)
HASH_FIND(hh_source_file, tmp_layout.storage.u.virt.source_file_hash_table, *pp,
tmp_size - 1, tmp_ent);
if (tmp_ent) {
/* Found source file name in previous mapping, use link to that mapping's source file
* name */
assert(tmp_ent >= tmp_layout.storage.u.virt.list &&
tmp_ent < &tmp_layout.storage.u.virt.list[u]);
tmp_layout.storage.u.virt.list[u].source_file_orig =
(size_t)(tmp_ent - tmp_layout.storage.u.virt.list);
tmp_layout.storage.u.virt.list[u].source_file_name = tmp_ent->source_file_name;
}
else {
/* Did not find source file name, copy it to the entry and add it to the hash table */
if (NULL == (tmp_layout.storage.u.virt.list[u].source_file_name =
(char *)H5MM_xstrdup((const char *)*pp)))
HGOTO_ERROR(H5E_PLIST, H5E_RESOURCE, FAIL, "can't duplicate source file name");
tmp_layout.storage.u.virt.list[u].source_file_orig = SIZE_MAX;
HASH_ADD_KEYPTR(hh_source_file, tmp_layout.storage.u.virt.source_file_hash_table,
tmp_layout.storage.u.virt.list[u].source_file_name, tmp_size - 1,
&tmp_layout.storage.u.virt.list[u]);
}
*pp += tmp_size;

/* Source dataset name */
/* Check for source dataset name in hash table */
tmp_ent = NULL;
tmp_size = strlen((const char *)*pp) + 1;
if (NULL ==
(tmp_layout.storage.u.virt.list[u].source_dset_name = (char *)H5MM_malloc(tmp_size)))
HGOTO_ERROR(H5E_PLIST, H5E_CANTALLOC, FAIL,
"unable to allocate memory for source dataset name");
H5MM_memcpy(tmp_layout.storage.u.virt.list[u].source_dset_name, *pp, tmp_size);
if (tmp_layout.storage.u.virt.list_nused > 0)
HASH_FIND(hh_source_dset, tmp_layout.storage.u.virt.source_dset_hash_table, *pp,
tmp_size - 1, tmp_ent);
if (tmp_ent) {
/* Found source dataset name in previous mapping, use link to that mapping's source
* dataset name */
assert(tmp_ent >= tmp_layout.storage.u.virt.list &&
tmp_ent < &tmp_layout.storage.u.virt.list[u]);
tmp_layout.storage.u.virt.list[u].source_dset_orig =
(size_t)(tmp_ent - tmp_layout.storage.u.virt.list);
tmp_layout.storage.u.virt.list[u].source_dset_name = tmp_ent->source_dset_name;
}
else {
/* Did not find source dataset name, copy it to the entry and add it to the hash table
*/
if (NULL == (tmp_layout.storage.u.virt.list[u].source_dset_name =
(char *)H5MM_xstrdup((const char *)*pp)))
HGOTO_ERROR(H5E_PLIST, H5E_RESOURCE, FAIL, "can't duplicate source dataset name");
tmp_layout.storage.u.virt.list[u].source_dset_orig = SIZE_MAX;
HASH_ADD_KEYPTR(hh_source_dset, tmp_layout.storage.u.virt.source_dset_hash_table,
tmp_layout.storage.u.virt.list[u].source_dset_name, tmp_size - 1,
&tmp_layout.storage.u.virt.list[u]);
}
*pp += tmp_size;

/* Source selection */
Expand Down
Loading