diff mbox series

[FFmpeg-devel,01/13] avcodec/cinepakenc: Cleanup generically after init failure

Message ID 20200829175626.11682-1-andreas.rheinhardt@gmail.com
State Accepted
Commit fea984d5c7a4ca92c1132ff468905fa026233967
Headers show
Series [FFmpeg-devel,01/13] avcodec/cinepakenc: Cleanup generically after init failure | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 29, 2020, 5:56 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/cinepakenc.c | 36 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)

Comments

Tomas Härdin Aug. 29, 2020, 6:06 p.m. UTC | #1
lör 2020-08-29 klockan 19:56 +0200 skrev Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/cinepakenc.c | 36 ++++++++++--------------------------
>  1 file changed, 10 insertions(+), 26 deletions(-)
> 
> diff --git a/libavcodec/cinepakenc.c b/libavcodec/cinepakenc.c
> index 6024df0fba..cc125ed39e 100644
> --- a/libavcodec/cinepakenc.c
> +++ b/libavcodec/cinepakenc.c

Looks good to me

/Tomas
diff mbox series

Patch

diff --git a/libavcodec/cinepakenc.c b/libavcodec/cinepakenc.c
index 6024df0fba..cc125ed39e 100644
--- a/libavcodec/cinepakenc.c
+++ b/libavcodec/cinepakenc.c
@@ -171,22 +171,22 @@  static av_cold int cinepak_encode_init(AVCodecContext *avctx)
     if (!(s->last_frame = av_frame_alloc()))
         return AVERROR(ENOMEM);
     if (!(s->best_frame = av_frame_alloc()))
-        goto enomem;
+        return AVERROR(ENOMEM);
     if (!(s->scratch_frame = av_frame_alloc()))
-        goto enomem;
+        return AVERROR(ENOMEM);
     if (avctx->pix_fmt == AV_PIX_FMT_RGB24)
         if (!(s->input_frame = av_frame_alloc()))
-            goto enomem;
+            return AVERROR(ENOMEM);
 
     if (!(s->codebook_input = av_malloc_array((avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4) * (avctx->width * avctx->height) >> 2, sizeof(*s->codebook_input))))
-        goto enomem;
+        return AVERROR(ENOMEM);
 
     if (!(s->codebook_closest = av_malloc_array((avctx->width * avctx->height) >> 2, sizeof(*s->codebook_closest))))
-        goto enomem;
+        return AVERROR(ENOMEM);;
 
     for (x = 0; x < (avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 4 : 3); x++)
         if (!(s->pict_bufs[x] = av_malloc((avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4) * (avctx->width * avctx->height) >> 2)))
-            goto enomem;
+            return AVERROR(ENOMEM);
 
     mb_count = avctx->width * avctx->height / MB_AREA;
 
@@ -199,13 +199,13 @@  static av_cold int cinepak_encode_init(AVCodecContext *avctx)
     frame_buf_size = CVID_HEADER_SIZE + s->max_max_strips * strip_buf_size;
 
     if (!(s->strip_buf = av_malloc(strip_buf_size)))
-        goto enomem;
+        return AVERROR(ENOMEM);
 
     if (!(s->frame_buf = av_malloc(frame_buf_size)))
-        goto enomem;
+        return AVERROR(ENOMEM);
 
     if (!(s->mb = av_malloc_array(mb_count, sizeof(mb_info))))
-        goto enomem;
+        return AVERROR(ENOMEM);
 
     av_lfg_init(&s->randctx, 1);
     s->avctx          = avctx;
@@ -252,23 +252,6 @@  static av_cold int cinepak_encode_init(AVCodecContext *avctx)
     s->max_strips = s->max_max_strips;
 
     return 0;
-
-enomem:
-    av_frame_free(&s->last_frame);
-    av_frame_free(&s->best_frame);
-    av_frame_free(&s->scratch_frame);
-    if (avctx->pix_fmt == AV_PIX_FMT_RGB24)
-        av_frame_free(&s->input_frame);
-    av_freep(&s->codebook_input);
-    av_freep(&s->codebook_closest);
-    av_freep(&s->strip_buf);
-    av_freep(&s->frame_buf);
-    av_freep(&s->mb);
-
-    for (x = 0; x < (avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 4 : 3); x++)
-        av_freep(&s->pict_bufs[x]);
-
-    return AVERROR(ENOMEM);
 }
 
 static int64_t calculate_mode_score(CinepakEncContext *s, int h,
@@ -1206,4 +1189,5 @@  AVCodec ff_cinepak_encoder = {
     .close          = cinepak_encode_end,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB24, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE },
     .priv_class     = &cinepak_class,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };