[FFmpeg-cvslog] avformat/utils: Fix memleak when decoding subtitle in find_stream_info

Andreas Rheinhardt git at videolan.org
Wed May 20 08:37:53 EEST 2020


ffmpeg | branch: release/4.2 | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Sat Apr 18 21:36:09 2020 +0200| [df88108c973d3844a1ae95d3bf8064f59926bc09] | committer: Andreas Rheinhardt

avformat/utils: Fix memleak when decoding subtitle in find_stream_info

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 at khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
(cherry picked from commit d026fef999f7e2491721b3878bea6e6da8b9f92e)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=df88108c973d3844a1ae95d3bf8064f59926bc09
---

 libavformat/utils.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index d51a97dd83..f32ced0116 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3092,6 +3092,8 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt,
         } 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;
         }



More information about the ffmpeg-cvslog mailing list