Skip to content

Commit fa133b1

Browse files
Fix possible USM allocation leak
1 parent fd4bab3 commit fa133b1

File tree

1 file changed

+8
-1
lines changed
  • dpctl/tensor/libtensor/include/kernels/sorting

1 file changed

+8
-1
lines changed

dpctl/tensor/libtensor/include/kernels/sorting/topk.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,16 @@ sycl::event topk_radix_impl(sycl::queue &exec_q,
475475
IndexTy *workspace = sycl::malloc_device<IndexTy>(
476476
padded_total_nelems + total_nelems, exec_q);
477477

478+
if (nullptr == workspace) {
479+
throw std::runtime_error(
480+
"Not enough device memory for radix sort topk");
481+
}
482+
478483
IndexTy *tmp_tp = sycl::malloc_device<IndexTy>(total_nelems, exec_q);
479484

480-
if (nullptr == workspace || nullptr == tmp_tp) {
485+
if (nullptr == tmp_tp) {
486+
using dpctl::tensor::alloc_utils::sycl_free_noexcept;
487+
sycl_free_noexcept(workspace, exec_q);
481488
throw std::runtime_error(
482489
"Not enough device memory for radix sort topk");
483490
}

0 commit comments

Comments
 (0)