From df24f4de714d74eacea2cc322c32b5122f9f55d0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 27 Nov 2022 10:45:15 +0100 Subject: lavc/libx264: unify cleanup in setup_frame() --- libavcodec/libx264.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 1e9ca73cdf..f776d65588 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -489,10 +489,8 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame *frame, sd = av_frame_get_side_data(frame, AV_FRAME_DATA_REGIONS_OF_INTEREST); if (sd) { ret = setup_roi(ctx, pic, bit_depth, frame, sd->data, sd->size); - if (ret < 0) { - free_picture(ctx); - return ret; - } + if (ret < 0) + goto fail; } if (x4->udu_sei) { @@ -504,16 +502,16 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame *frame, continue; tmp = av_fast_realloc(sei->payloads, &sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload)); if (!tmp) { - free_picture(ctx); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto fail; } sei->payloads = tmp; sei->sei_free = av_free; sei_payload = &sei->payloads[sei->num_payloads]; sei_payload->payload = av_memdup(side_data->data, side_data->size); if (!sei_payload->payload) { - free_picture(ctx); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto fail; } sei_payload->payload_size = side_data->size; sei_payload->payload_type = SEI_TYPE_USER_DATA_UNREGISTERED; @@ -523,6 +521,11 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame *frame, *ppic = pic; return 0; + +fail: + free_picture(ctx); + *ppic = NULL; + return ret; } static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, -- cgit v1.2.3