From e6b531af666be09ed342cc705ae4d6211cd28bc2 Mon Sep 17 00:00:00 2001 From: Eduardo Lima Mitev Date: Sun, 26 Jan 2020 22:25:17 +0000 Subject: [PATCH] turnip: Fix issues in tu_compute_pipeline_create() that may lead to crash The shader object is destroyed even if its creation failed. It is also not destroyed if its compilation or upload fails, leading to leaks. Finally, tu_compute_pipeline_create() should set output var pPipeline to VK_NULL_HANDLE if it fails. Avoids crash on dEQP-VK.api.object_management.alloc_callback_fail_multiple.compute_pipeline Reviewed-by: Kristian H. Kristensen Reviewed-by: Eric Anholt Tested-by: Marge Bot Part-of: --- src/freedreno/vulkan/tu_pipeline.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/freedreno/vulkan/tu_pipeline.c b/src/freedreno/vulkan/tu_pipeline.c index 8fe9b974db2..0aff134637a 100644 --- a/src/freedreno/vulkan/tu_pipeline.c +++ b/src/freedreno/vulkan/tu_pipeline.c @@ -2082,6 +2082,8 @@ tu_compute_pipeline_create(VkDevice device, struct tu_pipeline *pipeline; + *pPipeline = VK_NULL_HANDLE; + result = tu_pipeline_create(dev, pAllocator, &pipeline); if (result != VK_SUCCESS) return result; @@ -2100,7 +2102,7 @@ tu_compute_pipeline_create(VkDevice device, result = tu_shader_compile(dev, shader, NULL, &options, pAllocator); if (result != VK_SUCCESS) - return result; + goto fail; struct ir3_shader_variant *v = &shader->variants[0]; @@ -2109,7 +2111,7 @@ tu_compute_pipeline_create(VkDevice device, result = tu_compute_upload_shader(device, pipeline, shader); if (result != VK_SUCCESS) - return result; + goto fail; for (int i = 0; i < 3; i++) pipeline->compute.local_size[i] = v->shader->nir->info.cs.local_size[i]; @@ -2123,11 +2125,11 @@ tu_compute_pipeline_create(VkDevice device, return VK_SUCCESS; fail: - tu_shader_destroy(dev, shader, pAllocator); - if (result != VK_SUCCESS) { - tu_pipeline_finish(pipeline, dev, pAllocator); - vk_free2(&dev->alloc, pAllocator, pipeline); - } + if (shader) + tu_shader_destroy(dev, shader, pAllocator); + + tu_pipeline_finish(pipeline, dev, pAllocator); + vk_free2(&dev->alloc, pAllocator, pipeline); return result; } -- 2.30.2