Skip to content

Commit

Permalink
[UR] fix potential uncaught exception during adapter release (intel#1…
Browse files Browse the repository at this point in the history
…3929)

Found by Coverity.
  • Loading branch information
pbalcer committed May 28, 2024
1 parent 03b994e commit 190b15e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions sycl/plugins/unified_runtime/pi_unified_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ static void DieUnsupported() {

// Adapters may be released by piTearDown being called, or the global dtors
// being called first. Handle releasing the adapters exactly once.
static void releaseAdapters(std::vector<ur_adapter_handle_t> &Vec) {
static void releaseAdapters(std::vector<ur_adapter_handle_t> &Vec) noexcept {
static std::once_flag ReleaseFlag{};
std::call_once(ReleaseFlag, [&]() {
for (auto Adapter : Vec) {
urAdapterRelease(Adapter);
}
urLoaderTearDown();
});
try {
std::call_once(ReleaseFlag, [&]() {
for (auto Adapter : Vec) {
urAdapterRelease(Adapter);
}
urLoaderTearDown();
});
} catch (...) {
// Ignore any potential exceptions on teardown. Worst case scenario
// this just leaks some memory on exit.
}
}

struct AdapterHolder {
Expand Down

0 comments on commit 190b15e

Please sign in to comment.