[Ffmpeg-devel] Potential memory leak when using libavcodec.so

Burkhard Plaum plaum
Wed Aug 10 16:56:41 CEST 2005


One issue, I addressed some time ago....

The problem when using a shared libavcodec, is that the right time for calling
av_free_static() cannot always be determined. Reference counting doesn't 
work, because an application, which uses e.g. libquicktime, doesn't even know, 
if libavcodec is used or not (and it doesn't NEED to know it, that the nice
thing when using plugins). Putting av_free_static() into libquicktime
also doesn't work, because we never know, if lavc is used somewhere else in the
process (e.g. a transcoding application which uses lavc for en- and decoding).

For elf targets, there is a reliable, simple and completely harmless solution 
by putting a function into the fini section of the object file (by using 
__attribute__ ((destructor)) ). This function will always be called at the 
right time before lavc gets unloaded. Probably it also works for other targets 
than elf. I tested it for a long time, it never caused problems and valgrind 
reports 0 lost bytes. Would you accept such a patch?

Ahh, and yes, I'm already aware of the fact, that some people think, static
linking is the ultimate solution :)

Cheers

Burkhard





More information about the ffmpeg-devel mailing list