leaks when encoding (at least for asv, wma and aac). Fix also issue 1577. Originally committed as revision 21923 to svn://svn.ffmpeg.org/ffmpeg/trunk