[FFmpeg-devel] fix memory leak in frame_thread_encoder: occurs when close encoder without sending eof and receiving to end

Submitted by lee ju on Aug. 4, 2018, 10:19 a.m.

Details

Message ID PS1PR02MB124479D5A5FD7BCE5612964881220@PS1PR02MB1244.apcprd02.prod.outlook.com
State Accepted
Commit 6a0feafebe0e74bf7ce2d12a8177c670ebf2379a
Headers show

Commit Message

lee ju Aug. 4, 2018, 10:19 a.m.
---
 libavcodec/frame_thread_encoder.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Michael Niedermayer Aug. 5, 2018, 11:13 p.m.
On Sat, Aug 04, 2018 at 10:19:45AM +0000, lee ju wrote:
> ---
>  libavcodec/frame_thread_encoder.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)

probably ok

thx

[...]
Michael Niedermayer Aug. 15, 2018, 10:58 p.m.
On Mon, Aug 06, 2018 at 01:13:00AM +0200, Michael Niedermayer wrote:
> On Sat, Aug 04, 2018 at 10:19:45AM +0000, lee ju wrote:
> > ---
> >  libavcodec/frame_thread_encoder.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> 
> probably ok

will apply

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c
index 5ff3f7863c..55756c4c54 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -251,6 +251,23 @@  void ff_frame_thread_encoder_free(AVCodecContext *avctx){
          pthread_join(c->worker[i], NULL);
     }
 
+    while (av_fifo_size(c->task_fifo) > 0) {
+        Task task;
+        AVFrame *frame;
+        av_fifo_generic_read(c->task_fifo, &task, sizeof(task), NULL);
+        frame = task.indata;
+        av_frame_free(&frame);
+        task.indata = NULL;
+    }
+
+    for (i=0; i<BUFFER_SIZE; i++) {
+        if (c->finished_tasks[i].outdata != NULL) {
+            AVPacket *pkt = c->finished_tasks[i].outdata;
+            av_packet_free(&pkt);
+            c->finished_tasks[i].outdata = NULL;
+        }
+    }
+
     pthread_mutex_destroy(&c->task_fifo_mutex);
     pthread_mutex_destroy(&c->finished_task_mutex);
     pthread_mutex_destroy(&c->buffer_mutex);