Improve Memory Management of Result class

The way in which the Result class is used in Dawn can be fragile
with respect to memory management because the caller of AcquireError
must know they need to delete the returned pointer or a memory leak
will occur. We've had a couple of instances where developers have
accidentally left out the delete call and managed to get past code
review.

This CL changes the Result class so that it assumes the error is
allocated on the heap and forces the caller to use unique_ptr when
calling AcquireError.

Bug:dawn:320
Change-Id: I13ec953b0c37eaafbd6ce93c2f719b4743676acb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14960
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
This commit is contained in:
Rafael Cintron
2020-01-10 17:58:28 +00:00
committed by Commit Bot service account
parent 4950095ac9
commit 69c68d01b2
13 changed files with 194 additions and 255 deletions

View File

@@ -177,11 +177,10 @@ namespace dawn_native {
bool InstanceBase::ConsumedError(MaybeError maybeError) {
if (maybeError.IsError()) {
ErrorData* error = maybeError.AcquireError();
std::unique_ptr<ErrorData> error = maybeError.AcquireError();
ASSERT(error != nullptr);
dawn::InfoLog() << error->GetMessage();
delete error;
return true;
}