radv: fix AHB leak upon exportable allocation
authorYiwei Zhang <zzyiwei@chromium.org>
Sat, 22 May 2021 03:32:09 +0000 (03:32 +0000)
committerMarge Bot <eric+marge@anholt.net>
Tue, 25 May 2021 06:31:25 +0000 (06:31 +0000)
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 <zzyiwei@chromium.org>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10940>

src/amd/vulkan/radv_android.c

index f8064c0..fb3202a 100644 (file)
@@ -807,8 +807,10 @@ radv_create_ahb_memory(struct radv_device *device, struct radv_device_memory *me
    };
 
    VkResult result = radv_import_ahb_memory(device, mem, priority, &import_info);
-   if (result != VK_SUCCESS)
-      AHardwareBuffer_release(mem->android_hardware_buffer);
+
+   /* Release a reference to avoid leak for AHB allocation. */
+   AHardwareBuffer_release(mem->android_hardware_buffer);
+
    return result;
 #else /* RADV_SUPPORT_ANDROID_HARDWARE_BUFFER */
    return VK_ERROR_EXTENSION_NOT_PRESENT;