[MPlayer-users] MPlayer memory leak with lavc output

Michael Kohne mhkohne at moberg.com
Thu Jun 8 15:18:00 EEST 2017

On Wed, Jun 7, 2017 at 3:03 PM, Reimar Döffinger <Reimar.Doeffinger at gmx.de>

> valgrind is the most useful tool to debug the leaks it should (after e.g.
> aborting the command) tell quite clearly where all the memory was allocated.
> It is however fairly likely it is not a leak.
> Typical things that look like a leak:
> - index data for AVI which must be kept in memory and written at the end.
> It can get really large due to issues with "variable" frame rate or some
> audio codecs in AVI
> - audio and video are getting out of sync, requiring one to be buffered a
> lot. Playing the file while recording might show it by one or the other
> ending earlier. -noskip -mc 0 usually avoids the leak, but not other issues.

Well, I've solved the problem:
- Valgrind turned out to be useless for this. It choked on some
instructions in mencoder (I suspect some of the hand-written stuff). This
is a far from unknown problem with valgrind - it even tells you to how to
send a bug report with the offending instructions. I added my bug report to
their tracker just like many others, but since I'm working in 32 bit mode,
it's really not worth their fixing.

- I ended up using 'HeapUsage' (https://github.com/d99kris/heapusage),
which was much more amenable to working with mencoder.

- HeapUsage gave me a nice stack trace for the leak - an AVPacket in
encode_frame (libmpcodecs/ve_lavc.c) wasn't being cleaned up correctly (the
side_data was leaking).

- I checked the latest version of mencoder and this issue is clearly fixed
(the av_packet_unref at the end of the function), indicating that my
initial tests with the 2017-05-24 code were wrong in some way.

- It turns out that getting HeapUsage to deal with mencoder requires a
particular set of of compile/link option changes:
./configure --disable-gnutls --enable-debug --disable-relocatable
Modify the output config.mak file:
Remove -O options from CFLAGS & HOSTCFLAGS
Remove -Wl,--version-script,binary.ver from EXTRALIBS
Add -fno-inline to CFLAGS and CXXFLAGS

- If you don't get all the -O flags, and the version-script, then HeapUsage
still shows the leaked blocks, but the addresses it gives for where the
blocks were allocated are wrong and useless.



Michael Kohne
Senior Software Engineer
Office: 215.283.0860 x208
mhkohne at moberg.com

Transforming Neurocritical Care

Moberg Research, Inc.
224 S Maple Street, Ambler, PA 19002
24/7 Customer Support: 1-888-662-7246

More information about the MPlayer-users mailing list