PR #22753 opened by Kacper Michajłow (kasper93) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22753 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22753.patch
From 05ae0c98c060eb6d9e367b6ab4cd6088c2c92bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Wed, 8 Apr 2026 18:26:40 +0200 Subject: [PATCH 1/2] avcodec/vaapi_av1: fix leak of ref frames on init failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kacper Michajłow <[email protected]> --- libavcodec/vaapi_av1.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c index b8f5472c14..0e1b8c60e0 100644 --- a/libavcodec/vaapi_av1.c +++ b/libavcodec/vaapi_av1.c @@ -74,22 +74,32 @@ static int8_t vaapi_av1_get_bit_depth_idx(AVCodecContext *avctx) return bit_depth == 8 ? 0 : bit_depth == 10 ? 1 : 2; } +static av_cold int vaapi_av1_decode_uninit(AVCodecContext *avctx); + static av_cold int vaapi_av1_decode_init(AVCodecContext *avctx) { VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; + int ret = ff_vaapi_decode_init(avctx); + if (ret < 0) + return ret; + ctx->tmp_frame = av_frame_alloc(); - if (!ctx->tmp_frame) + if (!ctx->tmp_frame) { + vaapi_av1_decode_uninit(avctx); return AVERROR(ENOMEM); + } for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) { ctx->ref_tab[i].frame = av_frame_alloc(); - if (!ctx->ref_tab[i].frame) + if (!ctx->ref_tab[i].frame) { + vaapi_av1_decode_uninit(avctx); return AVERROR(ENOMEM); + } ctx->ref_tab[i].valid = 0; } - return ff_vaapi_decode_init(avctx); + return ret; } static av_cold int vaapi_av1_decode_uninit(AVCodecContext *avctx) -- 2.52.0 From df7c170fff072101822aaa98d0fbd80132e7b1b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Wed, 8 Apr 2026 18:28:56 +0200 Subject: [PATCH 2/2] avcodec/vaapi_av1: reorder functions to avoid fwd decl --- libavcodec/vaapi_av1.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c index 0e1b8c60e0..0d096401eb 100644 --- a/libavcodec/vaapi_av1.c +++ b/libavcodec/vaapi_av1.c @@ -74,7 +74,19 @@ static int8_t vaapi_av1_get_bit_depth_idx(AVCodecContext *avctx) return bit_depth == 8 ? 0 : bit_depth == 10 ? 1 : 2; } -static av_cold int vaapi_av1_decode_uninit(AVCodecContext *avctx); +static av_cold int vaapi_av1_decode_uninit(AVCodecContext *avctx) +{ + VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; + + av_frame_free(&ctx->tmp_frame); + + for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) + av_frame_free(&ctx->ref_tab[i].frame); + + av_freep(&ctx->slice_params); + + return ff_vaapi_decode_uninit(avctx); +} static av_cold int vaapi_av1_decode_init(AVCodecContext *avctx) { @@ -102,21 +114,6 @@ static av_cold int vaapi_av1_decode_init(AVCodecContext *avctx) return ret; } -static av_cold int vaapi_av1_decode_uninit(AVCodecContext *avctx) -{ - VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; - - av_frame_free(&ctx->tmp_frame); - - for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) - av_frame_free(&ctx->ref_tab[i].frame); - - av_freep(&ctx->slice_params); - - return ff_vaapi_decode_uninit(avctx); -} - - static int vaapi_av1_start_frame(AVCodecContext *avctx, av_unused const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
