clean up and handle null host when allocating ports