Skip to content

Commit 190b15e

Browse files
authored
[UR] fix potential uncaught exception during adapter release (#13929)
Found by Coverity.
1 parent 03b994e commit 190b15e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

sycl/plugins/unified_runtime/pi_unified_runtime.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ static void DieUnsupported() {
1919

2020
// Adapters may be released by piTearDown being called, or the global dtors
2121
// being called first. Handle releasing the adapters exactly once.
22-
static void releaseAdapters(std::vector<ur_adapter_handle_t> &Vec) {
22+
static void releaseAdapters(std::vector<ur_adapter_handle_t> &Vec) noexcept {
2323
static std::once_flag ReleaseFlag{};
24-
std::call_once(ReleaseFlag, [&]() {
25-
for (auto Adapter : Vec) {
26-
urAdapterRelease(Adapter);
27-
}
28-
urLoaderTearDown();
29-
});
24+
try {
25+
std::call_once(ReleaseFlag, [&]() {
26+
for (auto Adapter : Vec) {
27+
urAdapterRelease(Adapter);
28+
}
29+
urLoaderTearDown();
30+
});
31+
} catch (...) {
32+
// Ignore any potential exceptions on teardown. Worst case scenario
33+
// this just leaks some memory on exit.
34+
}
3035
}
3136

3237
struct AdapterHolder {

0 commit comments

Comments
 (0)