Skip to content

Commit c19383b

Browse files
author
Georgi Mirazchiyski
committed
[HIP] Catch and report bad_alloc errors for event object creation
1 parent 066341f commit c19383b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

source/adapters/hip/event.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,17 @@ 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+
try {
334+
EventPtr =
335+
std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeWithNative(
336+
hContext, reinterpret_cast<hipEvent_t>(hNativeEvent)));
337+
} catch (const std::bad_alloc &) {
338+
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
339+
} catch (...) {
340+
return UR_RESULT_ERROR_UNKNOWN;
341+
}
342+
343+
*phEvent = EventPtr.release();
335344

336345
return UR_RESULT_SUCCESS;
337346
}

0 commit comments

Comments
 (0)