Skip to content

Commit ecd62b7

Browse files
Use unique_ptr to manage lifetime of new copy of sycl::queue
This simplifies the code, and is in line with C++ coding practices. Thanks @AlexanderKalistratov for the suggestion.
1 parent a9c94e6 commit ecd62b7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

dpctl/apis/include/dpctl4pybind11.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,9 @@ class usm_memory : public py::object
759759
{
760760
auto const &api = ::dpctl::detail::dpctl_capi::get();
761761
DPCTLSyclUSMRef usm_ref = reinterpret_cast<DPCTLSyclUSMRef>(usm_ptr);
762-
sycl::queue *q_ptr = new sycl::queue(q);
763-
DPCTLSyclQueueRef QRef = reinterpret_cast<DPCTLSyclQueueRef>(q_ptr);
762+
auto q_uptr = std::make_unique<sycl::queue>(q);
763+
DPCTLSyclQueueRef QRef =
764+
reinterpret_cast<DPCTLSyclQueueRef>(q_uptr.get());
764765

765766
auto vacuous_destructor = []() {};
766767
py::object mock_owner = py::capsule(vacuous_destructor);
@@ -784,7 +785,6 @@ class usm_memory : public py::object
784785
}
785786
if (eptr) {
786787
Py_DECREF(_memory);
787-
delete q_ptr;
788788
std::rethrow_exception(eptr);
789789
}
790790
Py_MemoryObject *memobj =
@@ -799,9 +799,9 @@ class usm_memory : public py::object
799799
// std::shared_ptr and the deleter of the shared_ptr<void> is
800800
// supposed to free the USM allocation
801801
m_ptr = _memory;
802+
q_uptr.release();
802803
}
803804
else {
804-
delete q_ptr;
805805
Py_DECREF(_memory);
806806

807807
throw std::runtime_error(

0 commit comments

Comments
 (0)