PR #22713 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22713
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22713.patch

A failure while preparing a dither buffer leaves the newly allocated
buffer outside the cleanup range, leaking Vulkan resources. Make the
failure path cover the current buffer as well.

Signed-off-by: Zhao Zhili <[email protected]>


>From cf2d8bf9d0ef995d77c531cc88311bca0520aa34 Mon Sep 17 00:00:00 2001
From: Zhao Zhili <[email protected]>
Date: Sun, 5 Apr 2026 01:15:47 +0800
Subject: [PATCH] swscale/vulkan: fix dither buffer leak on mapping failure

A failure while preparing a dither buffer leaves the newly allocated
buffer outside the cleanup range, leaking Vulkan resources. Make the
failure path cover the current buffer as well.

Signed-off-by: Zhao Zhili <[email protected]>
---
 libswscale/vulkan/ops.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libswscale/vulkan/ops.c b/libswscale/vulkan/ops.c
index f81b78e52d..828cae43d0 100644
--- a/libswscale/vulkan/ops.c
+++ b/libswscale/vulkan/ops.c
@@ -171,16 +171,18 @@ static int create_dither_bufs(FFVulkanOpsCtx *s, 
VulkanPriv *p, SwsOpList *ops)
         av_assert0(p->nb_dither_buf + 1 <= MAX_DITHER_BUFS);
 
         int size = (1 << op->dither.size_log2);
-        err = ff_vk_create_buf(&s->vkctx, &p->dither_buf[p->nb_dither_buf],
+        int idx = p->nb_dither_buf;
+        err = ff_vk_create_buf(&s->vkctx, &p->dither_buf[idx],
                                size*size*sizeof(float), NULL, NULL,
                                VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                                VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
                                VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
         if (err < 0)
             goto fail;
+        p->nb_dither_buf++;
 
         float *dither_data;
-        err = ff_vk_map_buffer(&s->vkctx, &p->dither_buf[p->nb_dither_buf],
+        err = ff_vk_map_buffer(&s->vkctx, &p->dither_buf[idx],
                                (uint8_t **)&dither_data, 0);
         if (err < 0)
             goto fail;
@@ -192,8 +194,7 @@ static int create_dither_bufs(FFVulkanOpsCtx *s, VulkanPriv 
*p, SwsOpList *ops)
             }
         }
 
-        ff_vk_unmap_buffer(&s->vkctx, &p->dither_buf[p->nb_dither_buf], 1);
-        p->nb_dither_buf++;
+        ff_vk_unmap_buffer(&s->vkctx, &p->dither_buf[idx], 1);
     }
 
     return 0;
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to