1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 00:42:57 +00:00

demux_lavf: workaround minor ffmpeg memory leak

The sequence of avcodec_alloc_context3() / avcodec_copy_context() /
avcodec_close() / av_free() leaks some memory. So don't copy the context
and use it directly.

Originally avcodec_copy_context() was used to guarantee that libavformat
can't update the fields of the context during demuxing in order to make
things a little more robust, but it's not strictly needed, and
ffmpeg/ffplay don't do this anyway. Still might make the situation worse
should we move demuxing into a separate thread, though.
This commit is contained in:
wm4 2013-05-21 22:06:45 +02:00
parent b477c68aa0
commit 64a78cf314
2 changed files with 1 additions and 7 deletions

View File

@ -315,10 +315,6 @@ struct sh_stream *new_sh_stream(demuxer_t *demuxer, enum stream_type type)
static void free_sh_stream(struct sh_stream *sh)
{
if (sh->lav_headers) {
avcodec_close(sh->lav_headers);
av_free(sh->lav_headers);
}
}
sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid)

View File

@ -423,9 +423,7 @@ static void handle_stream(demuxer_t *demuxer, int i)
if (sh) {
sh->codec = mp_codec_from_av_codec_id(codec->codec_id);
sh->lav_headers = avcodec_alloc_context3(codec->codec);
assert(sh->lav_headers);
avcodec_copy_context(sh->lav_headers, codec);
sh->lav_headers = codec;
if (st->disposition & AV_DISPOSITION_DEFAULT)
sh->default_track = 1;