From bbcf114eea30368b6b97a3ef1b0c68cd75fb5a5c Mon Sep 17 00:00:00 2001
From: Alex Pokotilo <[email protected]>
Date: Wed, 12 Aug 2020 23:56:46 +1000
Subject: [PATCH] fix memory leak in qsvenc.c
"ff_qsv_enc_close" function called at the end of qsv encoding session and it frees q->async_fifo content content. "bs" item has two linked pointers and they should be freed the same way as in ff_qsv_encode.
To reproduce just close h264 encoding session with pending frames
---
libavcodec/qsvenc.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 1ed8f5d973..9ea2c7b1b9 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1612,6 +1612,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
{
QSVFrame *cur;
+#if QSV_VERSION_ATLEAST(1, 26)
+ mfxExtAVCEncodedFrameInfo *enc_info;
+ mfxExtBuffer **enc_buf;
+#endif
if (q->session)
MFXVideoENCODE_Close(q->session);
@@ -1640,8 +1644,16 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL);
- av_freep(&sync);
+#if QSV_VERSION_ATLEAST(1, 26)
+ if (avctx->codec_id == AV_CODEC_ID_H264) {
+ enc_buf = bs->ExtParam;
+ enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam);
+ av_freep(&enc_info);
+ av_freep(&enc_buf);
+ }
+#endif
av_freep(&bs);
+ av_freep(&sync);
av_packet_unref(&pkt);
}
av_fifo_free(q->async_fifo);
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".