ensure file descriptor is closed