diff --git a/unified-runtime/source/adapters/opencl/platform.cpp b/unified-runtime/source/adapters/opencl/platform.cpp index bec8b8a805991..b1140aadd43c4 100644 --- a/unified-runtime/source/adapters/opencl/platform.cpp +++ b/unified-runtime/source/adapters/opencl/platform.cpp @@ -72,7 +72,14 @@ urPlatformGet(ur_adapter_handle_t, uint32_t NumEntries, static std::mutex adapterPopulationMutex{}; ur_adapter_handle_t Adapter = nullptr; UR_RETURN_ON_FAILURE(urAdapterGet(1, &Adapter, nullptr)); - if (Adapter && !(Adapter->NumPlatforms)) { + if (!Adapter) { + // The only operation urAdapterGet really performs is allocating the adapter + // handle via new, so no adapter handle here almost certainly means memory + // problems. + return UR_RESULT_ERROR_OUT_OF_RESOURCES; + } + + if (Adapter->NumPlatforms == 0) { std::lock_guard guard{adapterPopulationMutex}; // It's possible for urPlatformGet, if ran on multiple threads, to enter