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
  0 siblings, 0 replies; only message 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] only message in thread

only message in thread, other threads:[~2025-10-28 12:29 UTC | newest]

Thread overview: (only message) (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

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