memory error when reinitializing buffer