Fix memory leak in ShaderModuleBase::MakeError

Change the ShaderModuleBase::MakeError to return a Ref<ShaderModuleBase>
rather than a naked pointer. This Ref will be used and finally detached in
DeviceBase::APICreateShaderModule.

Bug: chromium:1223546
Change-Id: Ie4213f091e37fdc61c6e1f0bb742e8787bcb4eb8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/58660
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
This commit is contained in:
Zhaoming Jiang 2021-07-20 01:17:38 +00:00 committed by Dawn LUCI CQ
parent ae5be1df34
commit 5af0a62e54
3 changed files with 4 additions and 3 deletions

View File

@ -844,6 +844,7 @@ namespace dawn_native {
std::unique_ptr<OwnedCompilationMessages> compilationMessages( std::unique_ptr<OwnedCompilationMessages> compilationMessages(
std::make_unique<OwnedCompilationMessages>()); std::make_unique<OwnedCompilationMessages>());
if (ConsumedError(CreateShaderModule(descriptor, compilationMessages.get()), &result)) { if (ConsumedError(CreateShaderModule(descriptor, compilationMessages.get()), &result)) {
DAWN_ASSERT(result == nullptr);
result = ShaderModuleBase::MakeError(this); result = ShaderModuleBase::MakeError(this);
} }
// Move compilation messages into ShaderModuleBase and emit tint errors and warnings // Move compilation messages into ShaderModuleBase and emit tint errors and warnings

View File

@ -1307,8 +1307,8 @@ namespace dawn_native {
} }
// static // static
ShaderModuleBase* ShaderModuleBase::MakeError(DeviceBase* device) { Ref<ShaderModuleBase> ShaderModuleBase::MakeError(DeviceBase* device) {
return new ShaderModuleBase(device, ObjectBase::kError); return AcquireRef(new ShaderModuleBase(device, ObjectBase::kError));
} }
bool ShaderModuleBase::HasEntryPoint(const std::string& entryPoint) const { bool ShaderModuleBase::HasEntryPoint(const std::string& entryPoint) const {

View File

@ -166,7 +166,7 @@ namespace dawn_native {
ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor); ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor);
~ShaderModuleBase() override; ~ShaderModuleBase() override;
static ShaderModuleBase* MakeError(DeviceBase* device); static Ref<ShaderModuleBase> MakeError(DeviceBase* device);
// Return true iff the program has an entrypoint called `entryPoint`. // Return true iff the program has an entrypoint called `entryPoint`.
bool HasEntryPoint(const std::string& entryPoint) const; bool HasEntryPoint(const std::string& entryPoint) const;