diff mbox series

[FFmpeg-devel,07/21] avformat/mpsubdec: Fix memleaks upon read_header failure

Message ID 20200322034756.29907-7-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
When allocating a new stream failed, the contents of an AVBPrint
as well as a subtitle queue would leak. This commit fixes this.

It also slightly simplifies the cleanup process by setting the
FF_INPUTFORMAT_HEADER_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
This patch and the other patches that involve subtitle queues should
only be applied after
https://ffmpeg.org/pipermail/ffmpeg-devel/2020-March/258790.html

 libavformat/mpsubdec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/mpsubdec.c b/libavformat/mpsubdec.c
index 82c73457ea..8bb1e97b8d 100644
--- a/libavformat/mpsubdec.c
+++ b/libavformat/mpsubdec.c
@@ -154,8 +154,10 @@  static int mpsub_read_header(AVFormatContext *s)
     }
 
     st = avformat_new_stream(s, NULL);
-    if (!st)
-        return AVERROR(ENOMEM);
+    if (!st) {
+        res = AVERROR(ENOMEM);
+        goto end;
+    }
     avpriv_set_pts_info(st, 64, pts_info.den, pts_info.num);
     st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
     st->codecpar->codec_id   = AV_CODEC_ID_TEXT;
@@ -163,9 +165,6 @@  static int mpsub_read_header(AVFormatContext *s)
     ff_subtitles_queue_finalize(s, &mpsub->q);
 
 end:
-    if (res < 0)
-        ff_subtitles_queue_clean(&mpsub->q);
-
     av_bprint_finalize(&buf, NULL);
     return res;
 }
@@ -201,4 +200,5 @@  AVInputFormat ff_mpsub_demuxer = {
     .read_seek2     = mpsub_read_seek,
     .read_close     = mpsub_read_close,
     .extensions     = "sub",
+    .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP,
 };