diff mbox series

[FFmpeg-devel,1/2] avcodec/proresenc_kostya: Cleanup generically after init failure

Message ID AM7PR03MB66602E76BAE0CC666768C1D28F2D9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 9d5810702c47369913f4616d3dd7c83f01ec754a
Headers show
Series [FFmpeg-devel,1/2] avcodec/proresenc_kostya: Cleanup generically after init failure | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 8, 2022, 10:37 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/proresenc_kostya.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

Andreas Rheinhardt Feb. 11, 2022, 9:28 a.m. UTC | #1
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/proresenc_kostya.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
> index 85651fce2a..08a874dd4e 100644
> --- a/libavcodec/proresenc_kostya.c
> +++ b/libavcodec/proresenc_kostya.c
> @@ -1274,25 +1274,19 @@ static av_cold int encode_init(AVCodecContext *avctx)
>          }
>  
>          ctx->slice_q = av_malloc(ctx->slices_per_picture * sizeof(*ctx->slice_q));
> -        if (!ctx->slice_q) {
> -            encode_close(avctx);
> +        if (!ctx->slice_q)
>              return AVERROR(ENOMEM);
> -        }
>  
>          ctx->tdata = av_mallocz(avctx->thread_count * sizeof(*ctx->tdata));
> -        if (!ctx->tdata) {
> -            encode_close(avctx);
> +        if (!ctx->tdata)
>              return AVERROR(ENOMEM);
> -        }
>  
>          for (j = 0; j < avctx->thread_count; j++) {
>              ctx->tdata[j].nodes = av_malloc((ctx->slices_width + 1)
>                                              * TRELLIS_WIDTH
>                                              * sizeof(*ctx->tdata->nodes));
> -            if (!ctx->tdata[j].nodes) {
> -                encode_close(avctx);
> +            if (!ctx->tdata[j].nodes)
>                  return AVERROR(ENOMEM);
> -            }
>              for (i = min_quant; i < max_quant + 2; i++) {
>                  ctx->tdata[j].nodes[i].prev_node = -1;
>                  ctx->tdata[j].nodes[i].bits      = 0;
> @@ -1415,5 +1409,5 @@ const AVCodec ff_prores_ks_encoder = {
>                        },
>      .priv_class     = &proresenc_class,
>      .profiles       = NULL_IF_CONFIG_SMALL(ff_prores_profiles),
> -    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
> +    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
>  };

Will apply this patchset later tonight unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index 85651fce2a..08a874dd4e 100644
--- a/libavcodec/proresenc_kostya.c
+++ b/libavcodec/proresenc_kostya.c
@@ -1274,25 +1274,19 @@  static av_cold int encode_init(AVCodecContext *avctx)
         }
 
         ctx->slice_q = av_malloc(ctx->slices_per_picture * sizeof(*ctx->slice_q));
-        if (!ctx->slice_q) {
-            encode_close(avctx);
+        if (!ctx->slice_q)
             return AVERROR(ENOMEM);
-        }
 
         ctx->tdata = av_mallocz(avctx->thread_count * sizeof(*ctx->tdata));
-        if (!ctx->tdata) {
-            encode_close(avctx);
+        if (!ctx->tdata)
             return AVERROR(ENOMEM);
-        }
 
         for (j = 0; j < avctx->thread_count; j++) {
             ctx->tdata[j].nodes = av_malloc((ctx->slices_width + 1)
                                             * TRELLIS_WIDTH
                                             * sizeof(*ctx->tdata->nodes));
-            if (!ctx->tdata[j].nodes) {
-                encode_close(avctx);
+            if (!ctx->tdata[j].nodes)
                 return AVERROR(ENOMEM);
-            }
             for (i = min_quant; i < max_quant + 2; i++) {
                 ctx->tdata[j].nodes[i].prev_node = -1;
                 ctx->tdata[j].nodes[i].bits      = 0;
@@ -1415,5 +1409,5 @@  const AVCodec ff_prores_ks_encoder = {
                       },
     .priv_class     = &proresenc_class,
     .profiles       = NULL_IF_CONFIG_SMALL(ff_prores_profiles),
-    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };