PR #22695 opened by Aleksoid1978 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22695 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22695.patch
https://trac.ffmpeg.org/ticket/11426 >From 5b6e147ae24d66df7ea1d37067a81ba929f490f3 Mon Sep 17 00:00:00 2001 From: Aleksoid <[email protected]> Date: Fri, 3 Apr 2026 11:15:06 +1000 Subject: [PATCH] libavcodec/qsvdec: Fixed memory leak on qsv_decode_flush(). --- libavcodec/qsvdec.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 5aacde9785..a89ff8fdf4 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -104,6 +104,8 @@ typedef struct QSVContext { int suggest_pool_size; int initialized; + int flush; + // options set by the caller int async_depth; int iopattern; @@ -413,6 +415,8 @@ static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVide q->frame_info = param->mfx.FrameInfo; + q->flush = 0; + if (!avctx->hw_frames_ctx) { ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->coded_width, 128), FFALIGN(avctx->coded_height, 64), 1); if (ret < 0) @@ -1058,6 +1062,20 @@ static int qsv_process_data(AVCodecContext *avctx, QSVContext *q, q->initialized = 1; } + if (q->flush) { + ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m); + if (ret < 0) { + if (ret == AVERROR(EAGAIN)) + av_log(avctx, AV_LOG_VERBOSE, "More data is required to decode header\n"); + else + av_log(avctx, AV_LOG_ERROR, "Error decoding header\n"); + goto reinit_fail; + } + + q->orig_pix_fmt = avctx->pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC); + q->flush = 0; + } + return qsv_decode(avctx, q, frame, got_frame, pkt); reinit_fail: @@ -1210,8 +1228,24 @@ static void qsv_decode_flush(AVCodecContext *avctx) qsv_clear_buffers(s); + if (s->qsv.session) { + mfxVideoParam param = { 0 }; + + int ret = MFXVideoDECODE_GetVideoParam(s->qsv.session, ¶m); + if (ret < 0) { + ff_qsv_print_error(avctx, ret, "MFX decode get param error"); + return; + } + + ret = MFXVideoDECODE_Reset(s->qsv.session, ¶m); + if (ret < 0) { + ff_qsv_print_error(avctx, ret, "MFX decode reset error"); + return; + } + } + s->qsv.orig_pix_fmt = AV_PIX_FMT_NONE; - s->qsv.initialized = 0; + s->qsv.flush = 1; } #define OFFSET(x) offsetof(QSVDecContext, x) -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
