Skip to content

Commit

Permalink
Fixes #450: Avoiding memory leak in `cuda::memory::virtual::set_acces…
Browse files Browse the repository at this point in the history
…s_mode()`

* Now using an `std::unique_ptr` rather than a raw `new`.
  • Loading branch information
eyalroz committed Mar 13, 2023
1 parent 3d33499 commit 9a9ef06
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cuda/api/multi_wrapper_impls/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,12 @@ inline void set_access_mode(
const Container<device_t>& devices,
access_mode_t access_mode)
{
auto descriptors = new CUmemAccessDesc[devices.size()];
auto descriptors = ::std::unique_ptr<CUmemAccessDesc[]>(new CUmemAccessDesc[devices.size()]);
for(::std::size_t i = 0; i < devices.size(); i++) {
descriptors[i] = {{CU_MEM_LOCATION_TYPE_DEVICE, devices[i].id()}, CUmemAccess_flags(access_mode)};
}
auto result = cuMemSetAccess(
device::address(fully_mapped_region.start()), fully_mapped_region.size(), descriptors, devices.size());
device::address(fully_mapped_region.start()), fully_mapped_region.size(), descriptors.get(), devices.size());
throw_if_error_lazy(result, "Failed setting the access mode to the virtual memory mapping to the range of size "
+ ::std::to_string(fully_mapped_region.size()) + " bytes at " + cuda::detail_::ptr_as_hex(fully_mapped_region.data()));
}
Expand Down

0 comments on commit 9a9ef06

Please sign in to comment.