]> git.sesse.net Git - ffmpeg/commitdiff
pthread_frame: do not share priv_data between multiple codec contexts
authorAnton Khirnov <anton@khirnov.net>
Sun, 15 Jan 2017 13:52:04 +0000 (14:52 +0100)
committerAnton Khirnov <anton@khirnov.net>
Fri, 10 Apr 2020 13:44:15 +0000 (15:44 +0200)
Specifically, between the user-facing one and the first frame thread
one.

This is fragile and dangerous, allocate separate private data for each
per-thread context.

libavcodec/pthread_frame.c

index 69671c90fb9f99ad99149d0dc783d9a7df21e98e..1ad43d438a481dcb929c2c0d98b0d7b925479c26 100644 (file)
@@ -702,7 +702,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
         av_packet_unref(&p->avpkt);
         av_freep(&p->released_buffers);
 
-        if (i && p->avctx) {
+        if (p->avctx) {
             if (codec->priv_class)
                 av_opt_free(p->avctx->priv_data);
             av_freep(&p->avctx->priv_data);
@@ -812,7 +812,7 @@ int ff_frame_thread_init(AVCodecContext *avctx)
         copy->internal->thread_ctx = p;
         copy->internal->last_pkt_props = &p->avpkt;
 
-        if (i) {
+        if (codec->priv_data_size) {
             copy->priv_data = av_mallocz(codec->priv_data_size);
             if (!copy->priv_data) {
                 err = AVERROR(ENOMEM);
@@ -825,9 +825,11 @@ int ff_frame_thread_init(AVCodecContext *avctx)
                 if (err < 0)
                     goto error;
             }
-            copy->internal->is_copy = 1;
         }
 
+        if (i)
+            copy->internal->is_copy = 1;
+
         if (codec->init)
             err = codec->init(copy);