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; }