From 2797c75426cf76bd2717fe0695d3f8e66cd41441 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Sat, 22 May 2021 03:21:05 +0000 Subject: [PATCH] anv: fix AHB leak upon exportable allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A successful AHardwareBuffer_allocate itself will increase a refcount on the newly allocated AHB. For the import case, the implementation must acquire a reference on the AHB. So if we layer the exportable allocation on top of AHB allocation and AHB import, we must release an AHB reference to avoid leak. Signed-off-by: Yiwei Zhang Reviewed-by: Tapani Pälli Part-of: --- src/intel/vulkan/anv_android.c | 11 +++++++++-- src/intel/vulkan/anv_device.c | 7 ------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index dee7b80cb45..c2a07531ec5 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -437,8 +437,15 @@ anv_create_ahw_memory(VkDevice device_h, if (AHardwareBuffer_allocate(&desc, &ahw) != 0) return VK_ERROR_OUT_OF_HOST_MEMORY; - mem->ahw = ahw; - return VK_SUCCESS; + const VkImportAndroidHardwareBufferInfoANDROID import_info = { + .buffer = ahw, + }; + result = anv_import_ahw_memory(device_h, mem, &import_info); + + /* Release a reference to avoid leak for AHB allocation. */ + AHardwareBuffer_release(ahw); + + return result; #else return VK_ERROR_EXTENSION_NOT_PRESENT; #endif diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 4281d823c23..81093afe285 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -3828,13 +3828,6 @@ VkResult anv_AllocateMemory( if (result != VK_SUCCESS) goto fail; - const VkImportAndroidHardwareBufferInfoANDROID import_info = { - .buffer = mem->ahw, - }; - result = anv_import_ahw_memory(_device, mem, &import_info); - if (result != VK_SUCCESS) - goto fail; - goto success; }