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

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sun Mar 22 05:47:42 EET 2020


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 at 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 --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,
 };
-- 
2.20.1



More information about the ffmpeg-devel mailing list