Always flush standard IO when exiting.

Fixes #3028.