mirror of https://github.com/mpv-player/mpv
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:
parent
7b4ccb3e9f
commit
0ed170ec0b
|
@ -282,6 +282,8 @@ static void convert_charset(struct demuxer *demuxer)
|
||||||
// libavformat transparently converts UTF-16 to UTF-8
|
// libavformat transparently converts UTF-16 to UTF-8
|
||||||
if (!mp_charset_is_utf16(cp) && !mp_charset_is_utf8(cp)) {
|
if (!mp_charset_is_utf16(cp) && !mp_charset_is_utf8(cp)) {
|
||||||
bstr conv = mp_iconv_to_utf8(demuxer->log, data, cp, MP_ICONV_VERBOSE);
|
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)
|
if (conv.start)
|
||||||
data = conv;
|
data = conv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,10 @@ struct lavc_conv *lavc_conv_create(struct mp_log *log, const char *codec_name,
|
||||||
if (!avctx)
|
if (!avctx)
|
||||||
goto error;
|
goto error;
|
||||||
avctx->extradata_size = extradata_len;
|
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)
|
if (avcodec_open2(avctx, codec, NULL) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
// Documented as "set by libavcodec", but there is no other way
|
// 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)
|
void lavc_conv_uninit(struct lavc_conv *priv)
|
||||||
{
|
{
|
||||||
avcodec_close(priv->avctx);
|
avsubtitle_free(&priv->cur);
|
||||||
av_free(priv->avctx);
|
avcodec_free_context(&priv->avctx);
|
||||||
talloc_free(priv);
|
talloc_free(priv);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue