Skip to content

Commit 8426544

Browse files
kekaczmabb-ur
authored andcommitted
Make ur_context_handle_t_ destructor non-throwing (#20887)
UR_CHECK_ERROR may throw or abort, which is unsafe to use from a destructor. If an exception escapes during stack unwinding, std::terminate would be called. Replace UR_CHECK_ERROR in ur_context_handle_t_ destructor with a non-throwing, best-effort cleanup. In debug builds, failures are reported via assert/log, while release builds avoid throwing from the destructor. fixes: intel/llvm#20811
1 parent 1dc130f commit 8426544

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

source/adapters/cuda/context.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ struct ur_context_handle_t_ : ur::cuda::handle_base {
107107
UR_CHECK_ERROR(urAdapterRetain(ur::cuda::adapter));
108108
};
109109

110-
~ur_context_handle_t_() {
110+
~ur_context_handle_t_() noexcept {
111111
if (MemoryPoolHost) {
112112
umfPoolDestroy(MemoryPoolHost);
113113
}
114114
if (MemoryProviderHost) {
115115
umfMemoryProviderDestroy(MemoryProviderHost);
116116
}
117-
UR_CHECK_ERROR(urAdapterRelease(ur::cuda::adapter));
117+
urAdapterRelease(ur::cuda::adapter);
118118
}
119119

120120
void invokeExtendedDeleters() {

source/adapters/hip/context.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ struct ur_context_handle_t_ : ur::hip::handle_base {
9696
UR_CHECK_ERROR(urAdapterRetain(ur::hip::adapter));
9797
};
9898

99-
~ur_context_handle_t_() {
100-
UR_CHECK_ERROR(urAdapterRelease(ur::hip::adapter));
101-
}
99+
~ur_context_handle_t_() noexcept { urAdapterRelease(ur::hip::adapter); }
102100

103101
ur_context_handle_t_(const ur_context_handle_t_ &) = delete;
104102

0 commit comments

Comments
 (0)