From 1302163264dcda7990cedbe5cd75318c0ef45130 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 23 Jun 2025 03:52:45 +0200 Subject: [PATCH 3/8] avcodec/fic: Avoid implicit av_frame_free()+av_frame_alloc() Use av_frame_replace() instead. Also remove the error message: It was highly misleading (as if av_frame_clone() duplicated the AVFrame data buffers instead of just creating a new reference). Signed-off-by: Andreas Rheinhardt --- libavcodec/fic.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/fic.c b/libavcodec/fic.c index a40fe1f27b..bf7b2ead2b 100644 --- a/libavcodec/fic.c +++ b/libavcodec/fic.c @@ -297,7 +297,7 @@ static int fic_decode_frame(AVCodecContext *avctx, AVFrame *rframe, /* Is it a skip frame? */ if (src[17]) { - if (!ctx->final_frame) { + if (!ctx->final_frame->data[0]) { av_log(avctx, AV_LOG_WARNING, "Initial frame is skipped\n"); return AVERROR_INVALIDDATA; } @@ -416,12 +416,9 @@ static int fic_decode_frame(AVCodecContext *avctx, AVFrame *rframe, break; } } - av_frame_free(&ctx->final_frame); - ctx->final_frame = av_frame_clone(ctx->frame); - if (!ctx->final_frame) { - av_log(avctx, AV_LOG_ERROR, "Could not clone frame buffer.\n"); - return AVERROR(ENOMEM); - } + ret = av_frame_replace(ctx->final_frame, ctx->frame); + if (ret < 0) + return ret; /* Make sure we use a user-supplied buffer. */ if ((ret = ff_reget_buffer(avctx, ctx->final_frame, 0)) < 0) { @@ -468,6 +465,9 @@ static av_cold int fic_decode_init(AVCodecContext *avctx) ctx->frame = av_frame_alloc(); if (!ctx->frame) return AVERROR(ENOMEM); + ctx->final_frame = av_frame_alloc(); + if (!ctx->final_frame) + return AVERROR(ENOMEM); return 0; } @@ -495,4 +495,5 @@ const FFCodec ff_fic_decoder = { .close = fic_decode_close, .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS, .p.priv_class = &fic_decoder_class, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, }; -- 2.45.2