If the hostname was already set, a typo in a test meant we were not freeing it. While we're at it, handle the unlikely possibility that the existing pointer is passed as the new value.