[MPlayer-dev-eng] [patch 5/5] Fix muxer memory leak

Reimar Döffinger Reimar.Doeffinger at gmx.de
Wed Jan 5 16:43:44 CET 2011


On Tue, Jan 04, 2011 at 09:35:06PM +0100, Tobias Diedrich wrote:
> Original patch by Sang-Uok Kum.
> 
> Signed-off-by: Tobias Diedrich <ranma at google.com>
> 
> Index: mplayer-patchset1/libmpdemux/muxer.c
> ===================================================================
> --- mplayer-patchset1.orig/libmpdemux/muxer.c	2010-12-21 21:03:16.199700000 +0100
> +++ mplayer-patchset1/libmpdemux/muxer.c	2010-12-21 21:05:11.009615000 +0100
> @@ -140,6 +140,8 @@
>            s->timer = buf->dts;
>            s->buffer = buf->buffer;
>            s->muxer->cont_write_chunk(s, buf->len, buf->flags, buf->dts, buf->pts);
> +          free(buf->buffer);
> +          buf->buffer = NULL;

I suspect the original idea was to reuse the allocated memory if
possible, but that is sure better than a memleak.

> @@ -148,6 +150,7 @@
>  
>          free(s->muxer->muxbuf);
>          s->muxer->muxbuf_num = 0;
> +        s->muxer->muxbuf = NULL;

That is not a memleak fix, though it is a fix.
However I see several more issues, for example I think the code still
can end up with a memleak and some unwritten final packets, there needs
to be some function that flushes all remaining buffered frames at the
end.
And after that it would be better to _not_ free muxbuf here but instead
give realloc a chance to reuse the memory area.


More information about the MPlayer-dev-eng mailing list