[FFmpeg-devel] [PATCH v1] avcodec/dnxhdenc: return error if av_malloc failed

James Almer jamrial at gmail.com
Sun Sep 22 17:15:51 EEST 2019


On 9/22/2019 11:06 AM, lance.lmwang at gmail.com wrote:
> From: Limin Wang <lance.lmwang at gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
> ---
>  libavcodec/dnxhdenc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
> index 41b8079..f144406 100644
> --- a/libavcodec/dnxhdenc.c
> +++ b/libavcodec/dnxhdenc.c
> @@ -365,7 +365,7 @@ fail:
>  static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
>  {
>      DNXHDEncContext *ctx = avctx->priv_data;
> -    int i, index, ret;
> +    int i = 1, index, ret;
>  
>      switch (avctx->pix_fmt) {
>      case AV_PIX_FMT_YUV422P:
> @@ -542,12 +542,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      if (avctx->active_thread_type == FF_THREAD_SLICE) {
>          for (i = 1; i < avctx->thread_count; i++) {
>              ctx->thread[i] = av_malloc(sizeof(DNXHDEncContext));
> +            if(!ctx->thread[i])
> +                goto fail;
>              memcpy(ctx->thread[i], ctx, sizeof(DNXHDEncContext));
>          }
>      }
>  
>      return 0;
>  fail:  // for FF_ALLOCZ_OR_GOTO
> +    avctx->thread_count = i;

This is unnecessary. All ctx->thread[] array elements are zero
initialized, so the av_freep() calls in dnxhd_encode_end() are safe for
those that were never allocated.

>      return AVERROR(ENOMEM);
>  }
>  
> 



More information about the ffmpeg-devel mailing list