]> git.sesse.net Git - ffmpeg/commitdiff
avformat/utils: Fix memleak when decoding subtitle in find_stream_info
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 18 Apr 2020 19:36:09 +0000 (21:36 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 20 Apr 2020 16:35:00 +0000 (18:35 +0200)
avformat_find_stream_info() may decode some frames to get stream
information. And when it does this for subtitles, the decoded subtitles
leak.

(Decoding subtitles was added in b1511e00f6fefde6cb31b2e17f7812cfac1c8bd6
for PGS subtitles. When PGS subtitles originate from a container that
exports every segment as a packet of its own, no output will be
generated when decoding a packet, because not enough input is available.
Yet when used with PGS subtitles in the Matroska form a single packet
contains enough data to generate output. Yet said output is not freed,
hence this leak.)

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/utils.c

index 4f777ba8495371e2d50854e54fd0f4bdbbe6d5af..2fb2309f68cd0027d1f081f5fe3f468e59b8ab47 100644 (file)
@@ -3126,6 +3126,8 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st,
         } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
             ret = avcodec_decode_subtitle2(avctx, &subtitle,
                                            &got_picture, &pkt);
+            if (got_picture)
+                avsubtitle_free(&subtitle);
             if (ret >= 0)
                 pkt.size = 0;
         }