fix a memory leak. use libavcodec's memory functions