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

lance.lmwang at gmail.com lance.lmwang at gmail.com
Sun Sep 22 17:06:16 EEST 2019


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;
     return AVERROR(ENOMEM);
 }
 
-- 
2.6.4



More information about the ffmpeg-devel mailing list