diff mbox series

[FFmpeg-devel,17/21] avformat/jacosubdec: Fix memleaks when queueing packet fails

Message ID 20200322034756.29907-17-andreas.rheinhardt@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,01/21] avformat/nsvdec: Use av_packet_move_ref() for packet ownership transfer | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt March 22, 2020, 3:47 a.m. UTC
If inserting a packet into a subtitle queue fails, said queue would leak
(because jacosub_read_close() which frees the queue was not called
automatically when reading the header fails); moreover, an AVBPrint
leaks, too. Both these leaks have been fixed, the former by setting the
FF_INPUTFORMAT_HEADER_CLEANUP flag.

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

Patch

diff --git a/libavformat/jacosubdec.c b/libavformat/jacosubdec.c
index 121c86d659..3e30118b8b 100644
--- a/libavformat/jacosubdec.c
+++ b/libavformat/jacosubdec.c
@@ -188,8 +188,10 @@  static int jacosub_read_header(AVFormatContext *s)
             AVPacket *sub;
 
             sub = ff_subtitles_queue_insert(&jacosub->q, line, len, merge_line);
-            if (!sub)
+            if (!sub) {
+                av_bprint_finalize(&header, NULL);
                 return AVERROR(ENOMEM);
+            }
             sub->pos = pos;
             merge_line = len > 1 && !strcmp(&line[len - 2], "\\\n");
             continue;
@@ -233,7 +235,7 @@  static int jacosub_read_header(AVFormatContext *s)
     /* general/essential directives in the extradata */
     ret = ff_bprint_to_codecpar_extradata(st->codecpar, &header);
     if (ret < 0)
-        goto fail;
+        return ret;
 
     /* SHIFT and TIMERES affect the whole script so packet timing can only be
      * done in a second pass */
@@ -244,9 +246,6 @@  static int jacosub_read_header(AVFormatContext *s)
     ff_subtitles_queue_finalize(s, &jacosub->q);
 
     return 0;
-fail:
-    jacosub_read_close(s);
-    return ret;
 }
 
 static int jacosub_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -272,4 +271,5 @@  AVInputFormat ff_jacosub_demuxer = {
     .read_packet    = jacosub_read_packet,
     .read_seek2     = jacosub_read_seek,
     .read_close     = jacosub_read_close,
+    .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP,
 };