]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/frame_thread_encoder: Fix segfault on allocation error
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 7 Feb 2021 09:58:25 +0000 (10:58 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 16 Feb 2021 21:11:53 +0000 (22:11 +0100)
Fixes a segfault from av_fifo_size(NULL) that happens in
ff_frame_thread_encoder_free if the fifo couldn't be allocted;
furthermore the mutexes and conditions that are destroyed in
ff_frame_thread_encoder_free are not even initialized at this point,
so don't call said function.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/frame_thread_encoder.c

index ee289c90e3f53b3e964a04c2de6f156bbf21dc01..9ca34e7ffb318874fe51c42a4029581270c22a87 100644 (file)
@@ -182,8 +182,10 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options){
     c->parent_avctx = avctx;
 
     c->task_fifo = av_fifo_alloc_array(BUFFER_SIZE, sizeof(Task));
-    if(!c->task_fifo)
-        goto fail;
+    if (!c->task_fifo) {
+        av_freep(&avctx->internal->frame_thread_encoder);
+        return AVERROR(ENOMEM);
+    }
 
     pthread_mutex_init(&c->task_fifo_mutex, NULL);
     pthread_mutex_init(&c->finished_task_mutex, NULL);