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.
This commit is contained in:
wm4 2016-01-18 11:46:28 +01:00
parent 7b4ccb3e9f
commit 0ed170ec0b
2 changed files with 8 additions and 3 deletions

View File

@ -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;
}

View File

@ -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);
}