PR #23099 opened by jiangjie URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23099 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23099.patch
Handle av_buffer_create() failure in qsv_dynamic_pool_alloc() via the common cleanup path so qsv_surface, child_frame, and handle_pairs_internal are released correctly. Also free the separately allocated VAAPI surface ID wrapper in the fail path of qsv_dynamic_pool_map_to(). >From e4e39839bd02d968fd65e002954edc5e0c834316 Mon Sep 17 00:00:00 2001 From: jiangjie <[email protected]> Date: Thu, 14 May 2026 22:01:05 +0800 Subject: [PATCH] avutil/hwcontext_qsv: free dynamic pool resources on allocation failures Handle av_buffer_create() failure in qsv_dynamic_pool_alloc() via the common cleanup path so qsv_surface, child_frame, and handle_pairs_internal are released correctly. Also free the separately allocated VAAPI surface ID wrapper in the fail path of qsv_dynamic_pool_map_to(). --- libavutil/hwcontext_qsv.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index b92c9cb0ad..8b0c99e733 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -430,6 +430,7 @@ static AVBufferRef *qsv_dynamic_pool_alloc(void *opaque, size_t size) AVHWFramesContext *child_frames_ctx; QSVSurface *qsv_surface = NULL; mfxHDLPair *handle_pairs_internal = NULL; + AVBufferRef *buf = NULL; int ret; if (!s->child_frames_ref) @@ -495,14 +496,23 @@ static AVBufferRef *qsv_dynamic_pool_alloc(void *opaque, size_t size) #endif qsv_surface->mfx_surface.Data.MemId = (mfxMemId)handle_pairs_internal; - return av_buffer_create((uint8_t *)qsv_surface, sizeof(*qsv_surface), - qsv_pool_release, ctx, 0); + buf = av_buffer_create((uint8_t *)qsv_surface, sizeof(*qsv_surface), + qsv_pool_release, ctx, 0); + if (!buf) + goto fail; + + return buf; fail: if (qsv_surface) { av_frame_free(&qsv_surface->child_frame); } +#if CONFIG_VAAPI + if (handle_pairs_internal && child_frames_ctx->device_ctx && + child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI) + av_freep(&handle_pairs_internal->first); +#endif av_freep(&qsv_surface); av_freep(&handle_pairs_internal); @@ -2313,6 +2323,10 @@ static int qsv_dynamic_pool_map_to(AVHWFramesContext *dst_ctx, return 0; fail: +#if CONFIG_VAAPI + if (handle_pairs_internal && src->format == AV_PIX_FMT_VAAPI) + av_freep(&handle_pairs_internal->first); +#endif av_freep(&handle_pairs_internal); av_freep(&surfaces_internal); return ret; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
