From 637a4b849a56a918ea54ba98f235e9867df8790e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Semenov=20Herman=20=28=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=29?= Date: Sun, 13 Oct 2024 00:49:07 +0300 Subject: [PATCH] radv: fix memleaks in radv_sqtt_reloc_graphics_shaders() Co-authored-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/layers/radv_sqtt_layer.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/amd/vulkan/layers/radv_sqtt_layer.c b/src/amd/vulkan/layers/radv_sqtt_layer.c index ee2d71822b6..eda1fdf00b2 100644 --- a/src/amd/vulkan/layers/radv_sqtt_layer.c +++ b/src/amd/vulkan/layers/radv_sqtt_layer.c @@ -139,6 +139,7 @@ radv_sqtt_reloc_graphics_shaders(struct radv_device *device, struct radv_graphic struct radv_shader_dma_submission *submission = NULL; struct radv_sqtt_shaders_reloc *reloc; uint32_t code_size = 0; + VkResult result; reloc = calloc(1, sizeof(*reloc)); if (!reloc) @@ -156,8 +157,8 @@ radv_sqtt_reloc_graphics_shaders(struct radv_device *device, struct radv_graphic /* Allocate memory for all shader binaries. */ reloc->alloc = radv_alloc_shader_memory(device, code_size, false, pipeline); if (!reloc->alloc) { - free(reloc); - return VK_ERROR_OUT_OF_DEVICE_MEMORY; + result = VK_ERROR_OUT_OF_DEVICE_MEMORY; + goto fail; } reloc->bo = reloc->alloc->arena->bo; @@ -169,8 +170,10 @@ radv_sqtt_reloc_graphics_shaders(struct radv_device *device, struct radv_graphic if (device->shader_use_invisible_vram) { submission = radv_shader_dma_get_submission(device, reloc->bo, slab_va, code_size); - if (!submission) - return VK_ERROR_UNKNOWN; + if (!submission) { + result = VK_ERROR_UNKNOWN; + goto fail; + } } for (int i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i) { @@ -194,8 +197,10 @@ radv_sqtt_reloc_graphics_shaders(struct radv_device *device, struct radv_graphic if (device->shader_use_invisible_vram) { uint64_t upload_seq = 0; - if (!radv_shader_dma_submit(device, submission, &upload_seq)) - return VK_ERROR_UNKNOWN; + if (!radv_shader_dma_submit(device, submission, &upload_seq)) { + result = VK_ERROR_UNKNOWN; + goto fail; + } for (int i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i) { struct radv_shader *shader = pipeline->base.shaders[i]; @@ -213,6 +218,12 @@ radv_sqtt_reloc_graphics_shaders(struct radv_device *device, struct radv_graphic pipeline->sqtt_shaders_reloc = reloc; return VK_SUCCESS; + +fail: + if (reloc->alloc) + radv_free_shader_memory(device, reloc->alloc); + free(reloc); + return result; } static void