Cherry-picked commit 7ee21b74 (issue #185).

Logout can produce a fatal error.