why don't you use av_freep ?