Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: cgutman via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: cgutman <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] lavc/vulkan_video: fix double-free and leak (PR #21173)
Date: Fri, 12 Dec 2025 04:01:24 -0000
Message-ID: <176551208490.39.6117111931075200546@2cb04c0e5124> (raw)

PR #21173 opened by cgutman
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21173
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21173.patch

I ran into this double-free when `ff_vk_alloc_mem()` failed in `ff_vk_video_common_init()` because the GPU was out of memory. In this case, `ff_vk_video_common_init()` calls `ff_vk_video_common_uninit()` in the `fail:` path which leaves dangling object handles in `FFVkVideoCommon`. Those get freed again when the destructor of `FFVulkanDecodeShared` calls `ff_vk_video_common_uninit()` a second time. I also included a simple leak fix that I found while investigating.

This should be cherry-picked into `release/8.0` and `release/7.1`, but I can also create new PRs for that if necessary.


>From d72a59dbd3df829e06b5229cab93e3989cdba909 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <aicommander@gmail.com>
Date: Thu, 11 Dec 2025 17:39:16 -0600
Subject: [PATCH 1/2] lavc/vulkan_video: fix double-free if ff_vk_decode_init()
 fails

ff_vk_video_common_init() calls ff_vk_video_common_uninit() on failure
which leaves dangling object handles. Those get freed again when the
destructor of FFVulkanDecodeShared calls ff_vk_video_common_uninit()
again.

Signed-off-by: Cameron Gutman <aicommander@gmail.com>
---
 libavcodec/vulkan_video.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vulkan_video.c b/libavcodec/vulkan_video.c
index 819940460f..66fc493ff1 100644
--- a/libavcodec/vulkan_video.c
+++ b/libavcodec/vulkan_video.c
@@ -349,17 +349,21 @@ av_cold void ff_vk_video_common_uninit(FFVulkanContext *s,
 
     av_freep(&common->mem);
 
-    if (common->layered_view)
+    if (common->layered_view) {
         vk->DestroyImageView(s->hwctx->act_dev, common->layered_view,
                              s->hwctx->alloc);
+        common->layered_view = VK_NULL_HANDLE;
+    }
 
     av_frame_free(&common->layered_frame);
 
     av_buffer_unref(&common->dpb_hwfc_ref);
 
-    if (common->yuv_sampler)
+    if (common->yuv_sampler) {
         vk->DestroySamplerYcbcrConversion(s->hwctx->act_dev, common->yuv_sampler,
                                           s->hwctx->alloc);
+        common->yuv_sampler = VK_NULL_HANDLE;
+    }
 }
 
 av_cold int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s,
-- 
2.49.1


>From cb01782b90bef5af569e3ff9940b9803f7033a8c Mon Sep 17 00:00:00 2001
From: Cameron Gutman <aicommander@gmail.com>
Date: Thu, 11 Dec 2025 21:52:37 -0600
Subject: [PATCH 2/2] lavc/vulkan_video: fix leak on CreateVideoSessionKHR
 failure

Signed-off-by: Cameron Gutman <aicommander@gmail.com>
---
 libavcodec/vulkan_video.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vulkan_video.c b/libavcodec/vulkan_video.c
index 66fc493ff1..d73479d14d 100644
--- a/libavcodec/vulkan_video.c
+++ b/libavcodec/vulkan_video.c
@@ -398,8 +398,10 @@ av_cold int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s,
     /* Create session */
     ret = vk->CreateVideoSessionKHR(s->hwctx->act_dev, session_create,
                                     s->hwctx->alloc, &common->session);
-    if (ret != VK_SUCCESS)
-        return AVERROR_EXTERNAL;
+    if (ret != VK_SUCCESS) {
+        err = AVERROR_EXTERNAL;
+        goto fail;
+    }
 
     /* Get memory requirements */
     ret = vk->GetVideoSessionMemoryRequirementsKHR(s->hwctx->act_dev,
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-12-12  4:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176551208490.39.6117111931075200546@2cb04c0e5124 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git