diff --git a/source/adapters/cuda/event.cpp b/source/adapters/cuda/event.cpp index 42f3e634e6..a6c2208e8f 100644 --- a/source/adapters/cuda/event.cpp +++ b/source/adapters/cuda/event.cpp @@ -290,8 +290,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle( std::unique_ptr EventPtr{nullptr}; - *phEvent = ur_event_handle_t_::makeWithNative( - hContext, reinterpret_cast(hNativeEvent)); + try { + EventPtr = + std::unique_ptr(ur_event_handle_t_::makeWithNative( + hContext, reinterpret_cast(hNativeEvent))); + } catch (const std::bad_alloc &) { + return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } catch (...) { + return UR_RESULT_ERROR_UNKNOWN; + } + + *phEvent = EventPtr.release(); return UR_RESULT_SUCCESS; }