diff --git a/.github/workflows/build-ffmpeg.yml b/.github/workflows/build-ffmpeg.yml index 7bdc48498..07e5042d2 100644 --- a/.github/workflows/build-ffmpeg.yml +++ b/.github/workflows/build-ffmpeg.yml @@ -248,6 +248,7 @@ jobs: git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/02-idr-on-amf.patch git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/03-amfenc-disable-buffering.patch git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/04-mfenc-lowlatency.patch + git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/05-qsv-session-leak.patch - name: Setup cross compilation id: cross diff --git a/ffmpeg_patches/ffmpeg/05-qsv-session-leak.patch b/ffmpeg_patches/ffmpeg/05-qsv-session-leak.patch new file mode 100644 index 000000000..f385981c9 --- /dev/null +++ b/ffmpeg_patches/ffmpeg/05-qsv-session-leak.patch @@ -0,0 +1,54 @@ +From a9ec49b4e728009c4bb4a2af7cb80a3c1ce6016c Mon Sep 17 00:00:00 2001 +From: Cameron Gutman +Date: Thu, 12 Jan 2023 17:49:29 -0600 +Subject: [PATCH] lavu/hwcontext_qsv: fix MFX session leak in hwdevice + +There was no device_uninit() implementation to handle freeing +the resources allocated in qsv_device_derive_from_child(). +--- + libavutil/hwcontext_qsv.c | 15 ++++++++++----- + 1 file changed, 10 insertions(+), 5 deletions(-) + +diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c +index 56dffa1f25..504d4f8a45 100644 +--- a/libavutil/hwcontext_qsv.c ++++ b/libavutil/hwcontext_qsv.c +@@ -220,6 +220,14 @@ static int qsv_fill_border(AVFrame *dst, const AVFrame *src) + return 0; + } + ++static void qsv_device_uninit(AVHWDeviceContext *ctx) ++{ ++ AVQSVDeviceContext *hwctx = ctx->hwctx; ++ ++ if (hwctx->session) ++ MFXClose(hwctx->session); ++} ++ + static int qsv_device_init(AVHWDeviceContext *ctx) + { + AVQSVDeviceContext *hwctx = ctx->hwctx; +@@ -1424,11 +1432,7 @@ static int qsv_frames_get_constraints(AVHWDeviceContext *ctx, + + static void qsv_device_free(AVHWDeviceContext *ctx) + { +- AVQSVDeviceContext *hwctx = ctx->hwctx; +- QSVDevicePriv *priv = ctx->user_opaque; +- +- if (hwctx->session) +- MFXClose(hwctx->session); ++ QSVDevicePriv *priv = ctx->user_opaque; + + av_buffer_unref(&priv->child_device_ctx); + av_freep(&priv); +@@ -1674,6 +1678,7 @@ const HWContextType ff_hwcontext_type_qsv = { + .device_create = qsv_device_create, + .device_derive = qsv_device_derive, + .device_init = qsv_device_init, ++ .device_uninit = qsv_device_uninit, + .frames_get_constraints = qsv_frames_get_constraints, + .frames_init = qsv_frames_init, + .frames_uninit = qsv_frames_uninit, +-- +2.39.0.windows.2 +