diff mbox series

[FFmpeg-devel,3/4] lavc/decode: deduplicate cleanup in ff_decode_receive_frame()

Message ID 20230105110756.473-3-anton@khirnov.net
State Accepted
Commit a1eec66867b40e5e0952a31ee43fdb273af5f5a5
Headers show
Series [FFmpeg-devel,1/4] lavc/ac3dec: fail when the sample rate is unset | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Jan. 5, 2023, 11:07 a.m. UTC
---
 libavcodec/decode.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 3e5be501b9..56ba06d5d5 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -685,10 +685,8 @@  int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
 
     if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
         ret = apply_cropping(avctx, frame);
-        if (ret < 0) {
-            av_frame_unref(frame);
-            return ret;
-        }
+        if (ret < 0)
+            goto fail;
     }
 
     avctx->frame_number++;
@@ -706,10 +704,8 @@  int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
                 avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate :
                                                                  avctx->sample_rate;
                 ret = av_channel_layout_copy(&avci->initial_ch_layout, &frame->ch_layout);
-                if (ret < 0) {
-                    av_frame_unref(frame);
-                    return ret;
-                }
+                if (ret < 0)
+                    goto fail;
                 break;
             }
         }
@@ -735,12 +731,15 @@  int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
                                             " drop count: %d \n",
                                             avctx->frame_number, frame->pts,
                                             avci->changed_frames_dropped);
-                av_frame_unref(frame);
-                return AVERROR_INPUT_CHANGED;
+                ret = AVERROR_INPUT_CHANGED;
+                goto fail;
             }
         }
     }
     return 0;
+fail:
+    av_frame_unref(frame);
+    return ret;
 }
 
 static void get_subtitle_defaults(AVSubtitle *sub)