Only close handles that are set to a valid handle value