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

The - supposedly outdated - documentation for av_vk_frame_alloc() was 
suggesting to use av_free() for releasing AVVkFrame, which 
was causing AVVkFrame->internal to leak, so a new and specialized function 
needs to be provided for releasing AVVkFrame.


This is my first PR on code.ffmpeg.org, please let me know in case something is 
missing or I should have done something before. 

Thanks


>From a8af2432569e193eb2a7b7e2c49a4fc9a734dfb7 Mon Sep 17 00:00:00 2001
From: softworkz <[email protected]>
Date: Wed, 5 Aug 2026 17:44:12 +0200
Subject: [PATCH] avutil/hwcontext_vulkan: Expose av_vk_frame_free()

Following the av_vk_frame_alloc() documentation to call av_free()
was causing AVVkFrame->internal to leak.

Signed-off-by: softworkz <[email protected]>
---
 doc/APIchanges               |  3 +++
 libavutil/hwcontext_vulkan.c | 13 ++++++++++++-
 libavutil/hwcontext_vulkan.h | 10 +++++++++-
 libavutil/version.h          |  2 +-
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 7907af9290..14036f8dcc 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2026-06-23.
 
 API changes, most recent first:
 
+2026-07-04 - xxxxxxxxxx - lavu 61.6.100 - hwcontext_vulkan.h
+  Add av_vk_frame_free().
+
 2026-07-04 - xxxxxxxxxx - lavc 63.7.100 - codec_id.h
   Add AV_CODEC_ID_PCM_DVDA.
 
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index ed27c78371..f1afc03c90 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2361,7 +2361,7 @@ static void vulkan_free_internal(VulkanDevicePriv *p, 
AVVkFrame *f)
     }
 #endif
 
-    if (internal->drm_sync_sem != VK_NULL_HANDLE)
+    if (p && internal->drm_sync_sem != VK_NULL_HANDLE)
         p->vkctx.vkfn.DestroySemaphore(p->p.act_dev, internal->drm_sync_sem,
                                         p->p.alloc);
 
@@ -2403,6 +2403,17 @@ static void vulkan_frame_free(AVHWFramesContext *hwfc, 
AVVkFrame *f)
     av_free(f);
 }
 
+void av_vk_frame_free(AVVkFrame **f)
+{
+    if (!f || !*f)
+        return;
+
+    if ((*f)->internal)
+        vulkan_free_internal(NULL, *f);
+
+    av_freep(f);
+}
+
 static void vulkan_frame_free_cb(void *opaque, uint8_t *data)
 {
     vulkan_frame_free(opaque, (AVVkFrame*)data);
diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h
index 87c2a2d28d..cb64e27495 100644
--- a/libavutil/hwcontext_vulkan.h
+++ b/libavutil/hwcontext_vulkan.h
@@ -327,10 +327,18 @@ struct AVVkFrame {
 
 /**
  * Allocates a single AVVkFrame and initializes everything as 0.
- * @note Must be freed via av_free()
+ * @note Must be freed via av_vk_frame_free()
  */
 AVVkFrame *av_vk_frame_alloc(void);
 
+/**
+ * Frees an AVVkFrame allocated via av_vk_frame_alloc(), and sets *f to NULL.
+ *
+ * Does not touch img[]/mem[]/sem[] so it is safe to call on an
+ * AVVkFrame wrapping images not owned by the frame.
+ */
+void av_vk_frame_free(AVVkFrame **f);
+
 /**
  * Returns the optimal per-plane Vulkan format for a given sw_format,
  * one for each plane.
diff --git a/libavutil/version.h b/libavutil/version.h
index d5bf20cf89..94b5e920b9 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  61
-#define LIBAVUTIL_VERSION_MINOR   5
+#define LIBAVUTIL_VERSION_MINOR   6
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.52.0

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

Reply via email to