Commit f9808ae2ce for ffmpeg
commit f9808ae2ce7ecc3d357fea3c94d32e6853217631
Author: Lynne <dev@lynne.ee>
Date: Sat Dec 5 15:50:53 2026 +0800
avutil/hwcontext_vulkan: fix leaking DRM mappings and their frames context
The sync submission when mapping from DRM runs on the frames context's
own execution pool, and kept a reference to the mapping. The mapping
references the frames context, so once mapping stopped, the frames
context, its last mappings and their DMA-BUFs were never freed.
Unmapping already waits on the frame's semaphores, so don't take a
reference.
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index c65a197ca9..2c9a9cfcfb 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -3944,12 +3944,19 @@ static int vulkan_map_from_drm_frame_sync(AVHWFramesContext *hwfc, AVFrame *dst,
drm_sync_sem, desc->nb_objects,
VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, 1);
+ /* No reference to the mapping: it references this frames context,
+ * which owns compute_exec. Unmapping waits on the frame's semaphores. */
+ AVFrame map_frame = {
+ .data[0] = dst->data[0],
+ .hw_frames_ctx = dst->hw_frames_ctx,
+ };
+
/* The imported DRM sync file only orders the external data, not this
* frame's earlier use by FFmpeg. The frame may be recycled from the
* pool while it is still in flight (and last used on another queue),
* so the map waits on its last signal, at ALL_COMMANDS, to be ordered
* after that previous use. */
- err = ff_vk_exec_add_dep_frame(&p->vkctx, exec, dst,
+ err = ff_vk_exec_add_dep_frame(&p->vkctx, exec, &map_frame,
VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT);
if (err < 0) {
@@ -3957,7 +3964,7 @@ static int vulkan_map_from_drm_frame_sync(AVHWFramesContext *hwfc, AVFrame *dst,
return err;
}
- ff_vk_frame_barrier(&p->vkctx, exec, dst, img_bar, &nb_img_bar,
+ ff_vk_frame_barrier(&p->vkctx, exec, &map_frame, img_bar, &nb_img_bar,
VK_PIPELINE_STAGE_2_NONE,
VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
((flags & AV_HWFRAME_MAP_READ) ?