[FFmpeg-devel] [PATCH v1] libavcodec/pthread_frame: fix crash that call method ff_frame_thread_init failed because of mem insufficient

javashu2012 at gmail.com javashu2012 at gmail.com
Fri Oct 16 10:55:01 EEST 2020


From: bevis <javashu2012 at gmail.com>

Signed-off-by: bevis <javashu2012 at gmail.com>
---
 libavcodec/pthread_frame.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index f8a01ad8cd..2babeb4a6a 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -795,6 +795,11 @@ int ff_frame_thread_init(AVCodecContext *avctx)
         pthread_cond_init(&p->progress_cond, NULL);
         pthread_cond_init(&p->output_cond, NULL);
 
+        if (!copy) {
+            err = AVERROR(ENOMEM);
+            goto error;
+        }
+
         p->frame = av_frame_alloc();
         if (!p->frame) {
             av_freep(&copy);
@@ -802,22 +807,18 @@ int ff_frame_thread_init(AVCodecContext *avctx)
             goto error;
         }
 
-        p->parent = fctx;
-        p->avctx  = copy;
-
-        if (!copy) {
+        AVCodecInternal *internal = av_malloc(sizeof(AVCodecInternal));
+        if (!internal) {
+            av_freep(&copy);
             err = AVERROR(ENOMEM);
             goto error;
         }
 
-        *copy = *src;
+        p->parent = fctx;
+        p->avctx  = copy;
 
-        copy->internal = av_malloc(sizeof(AVCodecInternal));
-        if (!copy->internal) {
-            copy->priv_data = NULL;
-            err = AVERROR(ENOMEM);
-            goto error;
-        }
+        *copy = *src;
+        copy->internal = internal;
         *copy->internal = *src->internal;
         copy->internal->thread_ctx = p;
         copy->internal->last_pkt_props = &p->avpkt;
-- 
2.21.1 (Apple Git-122.3)



More information about the ffmpeg-devel mailing list