diff --git a/include/openmc/hdf5_interface.h b/include/openmc/hdf5_interface.h index 468c25980c..ea4284cb82 100644 --- a/include/openmc/hdf5_interface.h +++ b/include/openmc/hdf5_interface.h @@ -162,13 +162,14 @@ void read_attribute(hid_t obj_id, const char* name, xt::xarray& arr) std::size_t size = 1; for (const auto x : shape) size *= x; - T* buffer = new T[size]; + std::vector buffer; + buffer.resize(size); // Read data from attribute - read_attr(obj_id, name, H5TypeMap::type_id, buffer); + read_attr(obj_id, name, H5TypeMap::type_id, buffer.data()); // Adapt array into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape); + arr = xt::adapt(buffer, shape); } // overload for std::string @@ -244,13 +245,14 @@ void read_dataset(hid_t dset, xt::xarray& arr, bool indep=false) std::size_t size = 1; for (const auto x : shape) size *= x; - T* buffer = new T[size]; + std::vector buffer; + buffer.resize(size); // Read data from attribute - read_dataset(dset, nullptr, H5TypeMap::type_id, buffer, indep); + read_dataset(dset, nullptr, H5TypeMap::type_id, buffer.data(), indep); // Adapt into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape); + arr = xt::adapt(buffer, shape); } template @@ -273,13 +275,14 @@ void read_dataset_as_shape(hid_t obj_id, const char* name, std::size_t size = 1; for (const auto x : arr.shape()) size *= x; - T* buffer = new T[size]; + std::vector buffer; + buffer.resize(size); // Read data from attribute - read_dataset(dset, nullptr, H5TypeMap::type_id, buffer, indep); + read_dataset(dset, nullptr, H5TypeMap::type_id, buffer.data(), indep); // Adapt into xarray - arr = xt::adapt(buffer, size, xt::acquire_ownership(), arr.shape()); + arr = xt::adapt(buffer, arr.shape()); close_dataset(dset); }