diff mbox

[FFmpeg-devel,4/9] pthread_frame: Unreference hw_frames_ctx on per-thread codec contexts

Message ID 20170318085606.26011-5-nfxjfg@googlemail.com
State Accepted
Commit fb69a8e1f124ee89e924344bfb7934937abed642
Headers show

Commit Message

wm4 March 18, 2017, 8:56 a.m. UTC
From: Mark Thompson <sw@jkqxz.net>

When decoding with threads enabled, the get_format callback will be
called with one of the per-thread codec contexts rather than with the
outer context.  If a hwaccel is in use too, this will add a reference
to the hardware frames context on that codec context, which will then
propagate to all of the other per-thread contexts for decoding.  Once
the decoder finishes, however, the per-thread contexts are not freed
normally, so these references leak.

Merges Libav commit fd0fae60.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
---
 libavcodec/pthread_frame.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 18f89ee73d..b16c1b9928 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -620,8 +620,11 @@  void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
             av_freep(&p->avctx->slice_offset);
         }
 
-        if (p->avctx)
+        if (p->avctx) {
             av_freep(&p->avctx->internal);
+            av_buffer_unref(&p->avctx->hw_frames_ctx);
+        }
+
         av_freep(&p->avctx);
     }