fix allocation loop termination