diff mbox series

[FFmpeg-devel,10/13] avcodec/frame_thread_encoder: Return proper error codes

Message ID AM7PR03MB66605B065362B3CD4088A0DF8FCE9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 5f6fcb0395382c73d253fafd3f44885e42a4d03a
Headers show
Series [FFmpeg-devel,01/13] avcodec/vp9: Do not destroy uninitialized mutexes/conditions
Related show

Checks

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

Commit Message

Andreas Rheinhardt Sept. 2, 2021, 3:41 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/frame_thread_encoder.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c
index 219d65cce7..e9a5a146ca 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -202,15 +202,19 @@  int ff_frame_thread_encoder_init(AVCodecContext *avctx)
     c->max_tasks = avctx->thread_count + 2;
     for (unsigned j = 0; j < c->max_tasks; j++) {
         if (!(c->tasks[j].indata  = av_frame_alloc()) ||
-            !(c->tasks[j].outdata = av_packet_alloc()))
+            !(c->tasks[j].outdata = av_packet_alloc())) {
+            ret = AVERROR(ENOMEM);
             goto fail;
+        }
     }
 
     for(i=0; i<avctx->thread_count ; i++){
         void *tmpv;
         thread_avctx = avcodec_alloc_context3(avctx->codec);
-        if(!thread_avctx)
+        if (!thread_avctx) {
+            ret = AVERROR(ENOMEM);
             goto fail;
+        }
         tmpv = thread_avctx->priv_data;
         *thread_avctx = *avctx;
         thread_avctx->priv_data = tmpv;
@@ -227,11 +231,12 @@  int ff_frame_thread_encoder_init(AVCodecContext *avctx)
         thread_avctx->thread_count = 1;
         thread_avctx->active_thread_type &= ~FF_THREAD_FRAME;
 
-        if (avcodec_open2(thread_avctx, avctx->codec, NULL) < 0)
+        if ((ret = avcodec_open2(thread_avctx, avctx->codec, NULL)) < 0)
             goto fail;
         av_assert0(!thread_avctx->internal->frame_thread_encoder);
         thread_avctx->internal->frame_thread_encoder = c;
-        if(pthread_create(&c->worker[i], NULL, worker, thread_avctx)) {
+        if ((ret = pthread_create(&c->worker[i], NULL, worker, thread_avctx))) {
+            ret = AVERROR(ret);
             goto fail;
         }
     }
@@ -245,7 +250,7 @@  fail:
     avctx->thread_count = i;
     av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n");
     ff_frame_thread_encoder_free(avctx);
-    return -1;
+    return ret;
 }
 
 void ff_frame_thread_encoder_free(AVCodecContext *avctx){