Skip to content

Commit 4c3f9ab

Browse files
committed
[HIP] Catch and report bad_alloc errors for event object creation
1 parent c4ae460 commit 4c3f9ab

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

source/adapters/hip/event.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
330330
ur_event_handle_t *phEvent) {
331331
std::ignore = pProperties;
332332

333-
*phEvent = ur_event_handle_t_::makeWithNative(
334-
hContext, reinterpret_cast<hipEvent_t>(hNativeEvent));
333+
std::unique_ptr<ur_event_handle_t_> EventPtr{nullptr};
334+
335+
try {
336+
EventPtr =
337+
std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeWithNative(
338+
hContext, reinterpret_cast<hipEvent_t>(hNativeEvent)));
339+
} catch (const std::bad_alloc &) {
340+
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
341+
} catch (...) {
342+
return UR_RESULT_ERROR_UNKNOWN;
343+
}
344+
345+
*phEvent = EventPtr.release();
335346

336347
return UR_RESULT_SUCCESS;
337348
}

0 commit comments

Comments
 (0)