Skip to content

Commit a92f90e

Browse files
authored
Merge pull request #117 from usnistgov/fix-malloc-cd-values
Fix incorrect allocation of cd_values array in get_dataset_filters()
2 parents 0d4c960 + d9a4e95 commit a92f90e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/hdf5_util.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,13 @@ val get_dataset_filters(hid_t loc_id, const std::string& dataset_name_string)
568568
H5Z_filter_t filter_id = H5Pget_filter2(plist_id, i, &flags, &nelements, cd_values, 256, name, NULL);
569569
val cd_values_out = val::array();
570570
if (nelements > 16) {
571-
unsigned int * full_cd_values = (unsigned int *)malloc(nelements);
571+
unsigned int * full_cd_values = (unsigned int *)malloc(nelements * sizeof(unsigned int));
572+
if (full_cd_values == NULL) {
573+
H5Dclose(ds_id);
574+
H5Pclose(plist_id);
575+
throw_error("error - malloc failed for filter cd_values!");
576+
return val::null();
577+
}
572578
H5Pget_filter2(plist_id, i, &flags, &nelements, full_cd_values, 256, name, NULL);
573579
for (size_t i = 0; i < nelements; i++) {
574580
cd_values_out.set(i, full_cd_values[i]);

0 commit comments

Comments
 (0)