summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Macnak <natsu@google.com>2022-03-02 16:31:58 -0800
committerCommit Bot <commit-bot@chromium.org>2022-03-18 06:50:05 +0000
commit4674c0ea746c719b1c10b72e529011cdce2d5fec (patch)
tree56b8b4ed1f47a3d1f4ac0f36a21e8a8d5881f2cb
parentfc5b72ff98ba96ed3b195c48ace545dab53a7208 (diff)
downloadminigbm-4674c0ea746c719b1c10b72e529011cdce2d5fec.tar.gz
gralloc: Avoid setting out handle before allocate finishes
... otherwise a buffer would be leaked if `mDriver->allocate()` succeeds but `initializeMetadata()` fails as the error handling in the multi-buffer `CrosGralloc4Allocate::allocate()` would fail to `mDriver->release();`. BUG=b:219757060 TEST=cvd start TEST=vts -m VtsHalGraphicsMapperV4_0Target Change-Id: I375da2c959dd9df2667503a040ed1dcbd2aa12b1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3501132 Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Tested-by: Jason Macnak <natsu@google.com> Commit-Queue: Jason Macnak <natsu@google.com>
-rw-r--r--cros_gralloc/gralloc4/CrosGralloc4Allocator.cc9
1 files changed, 4 insertions, 5 deletions
diff --git a/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc b/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc
index 6610c5e..43c0b0c 100644
--- a/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc
+++ b/cros_gralloc/gralloc4/CrosGralloc4Allocator.cc
@@ -95,18 +95,17 @@ Error CrosGralloc4Allocator::allocate(const BufferDescriptorInfo& descriptor, ui
return Error::NO_RESOURCES;
}
- outHandle->setTo(handle, /*shouldOwn=*/true);
-
cros_gralloc_handle_t crosHandle = cros_gralloc_convert_handle(handle);
- if (!crosHandle) {
- return Error::NO_RESOURCES;
- }
Error error = initializeMetadata(crosHandle, crosDescriptor);
if (error != Error::NONE) {
+ mDriver->release(handle);
+ native_handle_close(handle);
+ native_handle_delete(handle);
return error;
}
+ outHandle->setTo(handle, /*shouldOwn=*/true);
*outStride = crosHandle->pixel_stride;
return Error::NONE;