PR #22651 opened by Cray URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22651 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22651.patch
Currently, av_vk_frame_alloc() allocates an internal structure (AVVkFrame->internal) and creates a mutex. The header documentation advised to free the frame using av_free() function. However, av_free() only frees the top-level pointer and leaves the internal struct and mutex dangling. Solution: Dedicated av_vk_frame_free() function. This function cleans up the internal allocations via vulkan_free_internal(). i don't know if i should add av_vk_frame_free() to hwcontext_stub.c >From 56d7b5260cd7ba9b2a040539f7c74fa14fd2e0e4 Mon Sep 17 00:00:00 2001 From: Cray <[email protected]> Date: Sat, 28 Mar 2026 16:59:17 +0500 Subject: [PATCH] avutil/hwcontext_vulkan: add av_vk_frame_free() Introduces av_vk_frame_free() to properly clean up AVVkFrame. Since av_vk_frame_alloc() allocates an internal struct and mutex, the previously recommended av_free() caused memory leaks. Signed-off-by: Cray <[email protected]> --- doc/APIchanges | 3 +++ libavutil/hwcontext_vulkan.c | 12 ++++++++++++ libavutil/hwcontext_vulkan.h | 8 +++++++- libavutil/version.h | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 05771beb11..8ab3044f42 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28 API changes, most recent first: +2026-03-xx - xxxxxxxxxx - lavu 60.30.100 - hwcontext_vulkan.h + Add av_vk_frame_free(). + 2026-03-14 - xxxxxxxxxx - lavu 60.29.100 - hwcontext_vulkan.h Deprecate AVVulkanDeviceContext.lock_queue and AVVulkanDeviceContext.unlock_queue without replacement. diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 65e2256e2d..0aebf9a748 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -4891,6 +4891,18 @@ AVVkFrame *av_vk_frame_alloc(void) return f; } +void av_vk_frame_free(AVVkFrame **frame) +{ + if (!frame || !*frame) + return; + + if ((*frame)->internal) { + vulkan_free_internal(*frame); + } + + av_freep(frame); +} + const HWContextType ff_hwcontext_type_vulkan = { .type = AV_HWDEVICE_TYPE_VULKAN, .name = "Vulkan", diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h index b9a841a197..136c4147f5 100644 --- a/libavutil/hwcontext_vulkan.h +++ b/libavutil/hwcontext_vulkan.h @@ -376,10 +376,16 @@ 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 the AVVkFrame. Does not free or destroy img, mem, sem. + * @param frame frame to be freed. The pointer will be set to NULL. + */ +void av_vk_frame_free(AVVkFrame **frame); + /** * 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 6e2abf2ebf..40a7d8e300 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 60 -#define LIBAVUTIL_VERSION_MINOR 29 +#define LIBAVUTIL_VERSION_MINOR 30 #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]
