util: Avoid NPEs in closeSafely methods.