diff options
author | wm4 <wm4@nowhere> | 2013-05-21 22:06:45 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-05-21 22:07:13 +0200 |
commit | 64a78cf314379302e28ed8727c51aec82f9328a2 (patch) | |
tree | dd88a948f38df5cb09a7a7001729057272cfbe7c /demux | |
parent | b477c68aa084d202de24dc02cb008871d218f976 (diff) | |
download | mpv-64a78cf314379302e28ed8727c51aec82f9328a2.tar.bz2 mpv-64a78cf314379302e28ed8727c51aec82f9328a2.tar.xz |
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.
Diffstat (limited to 'demux')
-rw-r--r-- | demux/demux.c | 4 | ||||
-rw-r--r-- | demux/demux_lavf.c | 4 |
2 files changed, 1 insertions, 7 deletions
diff --git a/demux/demux.c b/demux/demux.c index b027f896de..c379ee4736 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -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) diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 279f7f7b33..5eebffc2f9 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -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; |