memory leak of buffer. Also i suspect avcodec needs alligned buffers. So please av_malloc them.