> -----Original Message-----
> From: 김현호(HYUN HO KIM) via ffmpeg-devel <[email protected]>
> Sent: Tuesday, October 28, 2025 20:28
> To: [email protected]
> Cc: 김현호(HYUN HO KIM) <[email protected]>
> Subject: [FFmpeg-devel] [PATCH] avcodec/qsv: Multiple calls to
> ff_qsv_init_session_frames() cause handle and memory leaks.
>
> Within qsvdec.c, ff_qsv_init_session_frames() is typically called twice during
> decoder initialization. Although qsv_create_mids() may be called if avctx-
> >hw_frames_ctx exists, this procedure causes memory and handle leaks
> because the existing created resources are merely set to NULL before
> ff_refstruct_unref() is called.
>
> Signed-off-by: Hyunho Kim <[email protected]>
> ---
> libavcodec/qsv.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 8a3dc95706..d8ddf85392 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -1133,13 +1133,13 @@ int ff_qsv_init_session_frames(AVCodecContext
> *avctx, mfxSession *psession,
> return ret;
>
> if (!opaque) {
> + /* clean up the exist mids */
s/exist/existing
> + ff_refstruct_unref(&qsv_frames_ctx->mids);
> qsv_frames_ctx->logctx = avctx;
> - qsv_frames_ctx->mids = NULL;
You may remove only this line, without any other changes.
Thanks
Haihao
> qsv_frames_ctx->nb_mids = 0;
>
> /* allocate the memory ids for the external frames */
> if (frames_hwctx->nb_surfaces) {
> - ff_refstruct_unref(&qsv_frames_ctx->mids);
> qsv_frames_ctx->mids = qsv_create_mids(qsv_frames_ctx-
> >hw_frames_ctx);
> if (!qsv_frames_ctx->mids)
> return AVERROR(ENOMEM);
> --
> 2.48.1.windows.1
>
> _______________________________________________
> ffmpeg-devel mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]