Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/qsv: Multiple calls to ff_qsv_init_session_frames() cause handle and memory leaks.
@ 2025-10-28 12:28 김현호(HYUN HO KIM) via ffmpeg-devel
  2025-11-21 16:33 ` [FFmpeg-devel] " Xiang, Haihao via ffmpeg-devel
  0 siblings, 1 reply; 2+ messages in thread
From: 김현호(HYUN HO KIM) via ffmpeg-devel @ 2025-10-28 12:28 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: 김현호(HYUN HO KIM)

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 <hh3.kim@hanwha.com>
---
 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 */
+        ff_refstruct_unref(&qsv_frames_ctx->mids);
         qsv_frames_ctx->logctx = avctx;
-        qsv_frames_ctx->mids = NULL;
         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 -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [FFmpeg-devel] Re: [PATCH] avcodec/qsv: Multiple calls to ff_qsv_init_session_frames() cause handle and memory leaks.
  2025-10-28 12:28 [FFmpeg-devel] [PATCH] avcodec/qsv: Multiple calls to ff_qsv_init_session_frames() cause handle and memory leaks 김현호(HYUN HO KIM) via ffmpeg-devel
@ 2025-11-21 16:33 ` Xiang, Haihao via ffmpeg-devel
  0 siblings, 0 replies; 2+ messages in thread
From: Xiang, Haihao via ffmpeg-devel @ 2025-11-21 16:33 UTC (permalink / raw)
  To: FFmpeg development discussions and patches
  Cc: 김현호(HYUN HO KIM), Xiang, Haihao



> -----Original Message-----
> From: 김현호(HYUN HO KIM) via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
> Sent: Tuesday, October 28, 2025 20:28
> To: ffmpeg-devel@ffmpeg.org
> Cc: 김현호(HYUN HO KIM) <hh3.kim@hanwha.com>
> 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 <hh3.kim@hanwha.com>
> ---
>  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 -- ffmpeg-devel@ffmpeg.org
> To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-21 16:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-28 12:28 [FFmpeg-devel] [PATCH] avcodec/qsv: Multiple calls to ff_qsv_init_session_frames() cause handle and memory leaks 김현호(HYUN HO KIM) via ffmpeg-devel
2025-11-21 16:33 ` [FFmpeg-devel] " Xiang, Haihao via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git