diff mbox series

[FFmpeg-devel,16/26] avformat/sccdec: Fix memleak upon read header failure

Message ID 20200614223656.21338-16-andreas.rheinhardt@gmail.com
State Accepted
Commit f3c63e67bb00fa7d96595203d01a576df651e275
Headers show
Series [FFmpeg-devel,01/26] avformat/matroskadec: Move AVBufferRef instead of copying, fix memleak
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt June 14, 2020, 10:36 p.m. UTC
The already parsed subtitles (contained in an FFDemuxSubtitlesQueue)
would leak if an error happened upon reading a subsequent subtitle.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/sccdec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/sccdec.c b/libavformat/sccdec.c
index 0eb1dd307e..72f47f70de 100644
--- a/libavformat/sccdec.c
+++ b/libavformat/sccdec.c
@@ -144,7 +144,7 @@  try_again:
 
                 sub = ff_subtitles_queue_insert(&scc->q, out, i, 0);
                 if (!sub)
-                    return AVERROR(ENOMEM);
+                    goto fail;
 
                 current_pos += i;
                 sub->pos = current_pos;
@@ -159,7 +159,7 @@  try_again:
 
         sub = ff_subtitles_queue_insert(&scc->q, out, i, 0);
         if (!sub)
-            return AVERROR(ENOMEM);
+            goto fail;
 
         sub->pos = current_pos;
         sub->pts = ts_start;
@@ -178,6 +178,9 @@  try_again:
     ff_subtitles_queue_finalize(s, &scc->q);
 
     return ret;
+fail:
+    ff_subtitles_queue_clean(&scc->q);
+    return AVERROR(ENOMEM);
 }
 
 static int scc_read_packet(AVFormatContext *s, AVPacket *pkt)