Fix memory leak in vkDestroyImage
When swapchain images were being destroyed on Android,
the backing memory was not being destroyed, causing a crash.
Tests: dEQP-VK.wsi.android.swapchain.create.min_image_count
Bug: 133346002
Change-Id: Ib2383a6c41ac2917f6e6630eca96e5c180996507
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31870
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Tested-by: Hernan Liatis <hliatis@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp
index 891ba3c..c339caf 100644
--- a/src/Vulkan/libVulkan.cpp
+++ b/src/Vulkan/libVulkan.cpp
@@ -1053,6 +1053,16 @@
device, image.get(), pAllocator);
vk::destroy(image, pAllocator);
+
+#ifdef __ANDROID__
+ auto it = androidSwapchainMap.find(image);
+
+ if (it != androidSwapchainMap.end())
+ {
+ vk::destroy((it->second).imageMemory, nullptr);
+ androidSwapchainMap.erase(it);
+ }
+#endif
}
VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout(VkDevice device, VkImage image, const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout)