Fix memory corruption bug when buffer* is reallocated.