Fix use-after-move with AddOrGetCached*Pipeline
Fixed: dawn:2415
Change-Id: If1bdc8a03263202d41947bc8336ad2f79e777b1f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/175300
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: dan sinclair <dsinclair@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index 1b9f09b..b896e62 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -2158,10 +2158,10 @@
// AddOrGetCachedComputePipeline() to avoid deadlock because many places calling
// that method might already have the lock held. For example,
// APICreateComputePipeline()
- auto deviceLock(pipeline->GetDevice()->GetScopedLock());
- if (pipeline->GetDevice()->GetState() == State::Alive) {
- pipeline =
- pipeline->GetDevice()->AddOrGetCachedComputePipeline(std::move(pipeline));
+ DeviceBase* device = pipeline->GetDevice();
+ auto deviceLock(device->GetScopedLock());
+ if (device->GetState() == State::Alive) {
+ pipeline = device->AddOrGetCachedComputePipeline(std::move(pipeline));
}
}
callback(WGPUCreatePipelineAsyncStatus_Success, ToAPI(ReturnToAPI(std::move(pipeline))),
@@ -2205,9 +2205,10 @@
// Note: we don't lock inside AddOrGetCachedRenderPipeline() to avoid deadlock
// because many places calling that method might already have the lock held. For
// example, APICreateRenderPipeline()
- auto deviceLock(pipeline->GetDevice()->GetScopedLock());
- if (pipeline->GetDevice()->GetState() == State::Alive) {
- pipeline = pipeline->GetDevice()->AddOrGetCachedRenderPipeline(std::move(pipeline));
+ DeviceBase* device = pipeline->GetDevice();
+ auto deviceLock(device->GetScopedLock());
+ if (device->GetState() == State::Alive) {
+ pipeline = device->AddOrGetCachedRenderPipeline(std::move(pipeline));
}
}
callback(WGPUCreatePipelineAsyncStatus_Success, ToAPI(ReturnToAPI(std::move(pipeline))), "",