From 08a8d3288f949bfbadc12549296fe745eda33daa Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Fri, 5 Oct 2018 21:07:44 -0400 Subject: [PATCH] Fix HDF5/xtensor mismatched free/delete error --- include/openmc/hdf5_interface.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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); }