Fixes an issue in the allocation of ports which causes a portion of a user-specified port range to be utilized. Reported by Emil Ivov.