diff options
author | wm4 <wm4@nowhere> | 2016-01-18 11:46:28 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-01-18 11:46:28 +0100 |
commit | 0ed170ec0b7483568ad82c936afee7803a533908 (patch) | |
tree | df2023695f49d775dfd6c2c22aa1b58b9d399562 | |
parent | 7b4ccb3e9f58a0745b58e473ee6e60b381242813 (diff) | |
download | mpv-0ed170ec0b7483568ad82c936afee7803a533908.tar.bz2 mpv-0ed170ec0b7483568ad82c936afee7803a533908.tar.xz |
sub: fix memory leaks
demux_lavf.c leaked the complete subtitle data if it was put through
iconv.
lavc_conv.c leaked AVCodecContext.subtitle_header (set by libavcodec),
which is fixed by using avcodec_free_context(). It also leaked the
subtitle that was decoded last.
-rw-r--r-- | demux/demux_lavf.c | 2 | ||||
-rw-r--r-- | sub/lavc_conv.c | 9 |
2 files changed, 8 insertions, 3 deletions
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 1b3105170d..8cd525b685 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -282,6 +282,8 @@ static void convert_charset(struct demuxer *demuxer) // libavformat transparently converts UTF-16 to UTF-8 if (!mp_charset_is_utf16(cp) && !mp_charset_is_utf8(cp)) { bstr conv = mp_iconv_to_utf8(demuxer->log, data, cp, MP_ICONV_VERBOSE); + if (conv.start && conv.start != data.start) + talloc_steal(alloc, conv.start); if (conv.start) data = conv; } diff --git a/sub/lavc_conv.c b/sub/lavc_conv.c index 42f9563391..f6c9b5abe2 100644 --- a/sub/lavc_conv.c +++ b/sub/lavc_conv.c @@ -78,7 +78,10 @@ struct lavc_conv *lavc_conv_create(struct mp_log *log, const char *codec_name, if (!avctx) goto error; avctx->extradata_size = extradata_len; - avctx->extradata = talloc_memdup(priv, extradata, extradata_len); + avctx->extradata = av_malloc(extradata_len); + if (!avctx->extradata) + goto error; + memcpy(avctx->extradata, extradata, extradata_len); if (avcodec_open2(avctx, codec, NULL) < 0) goto error; // Documented as "set by libavcodec", but there is no other way @@ -264,7 +267,7 @@ void lavc_conv_reset(struct lavc_conv *priv) void lavc_conv_uninit(struct lavc_conv *priv) { - avcodec_close(priv->avctx); - av_free(priv->avctx); + avsubtitle_free(&priv->cur); + avcodec_free_context(&priv->avctx); talloc_free(priv); } |