diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-08-29 09:37:17 +0300 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-08-30 03:55:43 +0300 |
commit | fea984d5c7a4ca92c1132ff468905fa026233967 (patch) | |
tree | 686ca01f3386a35b4a56fff12eb30dfe5f6504b0 /libavcodec | |
parent | 5ff2ff6bd9cd9e08729060d330e381a09972c498 (diff) |
avcodec/cinepakenc: Cleanup generically after init failure
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/cinepakenc.c | 36 |
1 files 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 @@ -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, }; |