summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeil Fortner <fortnern@gmail.com>2022-09-14 16:10:05 (GMT)
committerGitHub <noreply@github.com>2022-09-14 16:10:05 (GMT)
commitb5598575bb8a2495d6f306233b00d612258ad718 (patch)
treec23a15b5f7ea5320e09ebd682eb6ce0e439be88c /src
parentfe9c07fd90d7ccf91776672fdc75cc5675d6ed58 (diff)
downloadhdf5-b5598575bb8a2495d6f306233b00d612258ad718.zip
hdf5-b5598575bb8a2495d6f306233b00d612258ad718.tar.gz
hdf5-b5598575bb8a2495d6f306233b00d612258ad718.tar.bz2
Fix memory bug in selection I/O (#2096)
* Fix memory bug in selection I/O * Change error messages for calls to H5I_remove() in H5FD_read/write_selection()
Diffstat (limited to 'src')
-rw-r--r--src/H5FDint.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/H5FDint.c b/src/H5FDint.c
index d8c6203..91ce6c6 100644
--- a/src/H5FDint.c
+++ b/src/H5FDint.c
@@ -1170,8 +1170,8 @@ H5FD_read_selection(H5FD_t *file, H5FD_mem_t type, uint32_t count, H5S_t **mem_s
if ((file_space_ids[num_spaces] = H5I_register(H5I_DATASPACE, file_spaces[num_spaces], TRUE)) <
0) {
- if (H5I_dec_app_ref(mem_space_ids[num_spaces]) < 0)
- HDONE_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "problem freeing id")
+ if (NULL == H5I_remove(mem_space_ids[num_spaces]))
+ HDONE_ERROR(H5E_VFL, H5E_CANTREMOVE, FAIL, "problem removing id")
HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register dataspace ID")
}
}
@@ -1200,12 +1200,14 @@ done:
}
}
- /* Cleanup dataspace arrays */
+ /* Cleanup dataspace arrays. Use H5I_remove() so we only close the IDs and
+ * not the underlying dataspaces, which were not created by this function.
+ */
for (i = 0; i < num_spaces; i++) {
- if (H5I_dec_app_ref(mem_space_ids[i]) < 0)
- HDONE_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "problem freeing id")
- if (H5I_dec_app_ref(file_space_ids[i]) < 0)
- HDONE_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "problem freeing id")
+ if (NULL == H5I_remove(mem_space_ids[i]))
+ HDONE_ERROR(H5E_VFL, H5E_CANTREMOVE, FAIL, "problem removing id")
+ if (NULL == H5I_remove(file_space_ids[i]))
+ HDONE_ERROR(H5E_VFL, H5E_CANTREMOVE, FAIL, "problem removing id")
}
if (mem_space_ids != mem_space_ids_local)
mem_space_ids = H5MM_xfree(mem_space_ids);
@@ -1805,8 +1807,8 @@ H5FD_write_selection(H5FD_t *file, H5FD_mem_t type, uint32_t count, H5S_t **mem_
if ((file_space_ids[num_spaces] = H5I_register(H5I_DATASPACE, file_spaces[num_spaces], TRUE)) <
0) {
- if (H5I_dec_app_ref(mem_space_ids[num_spaces]) < 0)
- HDONE_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "problem freeing id")
+ if (NULL == H5I_remove(mem_space_ids[num_spaces]))
+ HDONE_ERROR(H5E_VFL, H5E_CANTREMOVE, FAIL, "problem removing id")
HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register dataspace ID")
}
}
@@ -1835,12 +1837,14 @@ done:
}
}
- /* Cleanup dataspace arrays */
+ /* Cleanup dataspace arrays. Use H5I_remove() so we only close the IDs and
+ * not the underlying dataspaces, which were not created by this function.
+ */
for (i = 0; i < num_spaces; i++) {
- if (H5I_dec_app_ref(mem_space_ids[i]) < 0)
- HDONE_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "problem freeing id")
- if (H5I_dec_app_ref(file_space_ids[i]) < 0)
- HDONE_ERROR(H5E_VFL, H5E_CANTDEC, FAIL, "problem freeing id")
+ if (NULL == H5I_remove(mem_space_ids[i]))
+ HDONE_ERROR(H5E_VFL, H5E_CANTREMOVE, FAIL, "problem removing id")
+ if (NULL == H5I_remove(file_space_ids[i]))
+ HDONE_ERROR(H5E_VFL, H5E_CANTREMOVE, FAIL, "problem removing id")
}
if (mem_space_ids != mem_space_ids_local)
mem_space_ids = H5MM_xfree(mem_space_ids);