Iostreams: In chains, clean up properly when close throws in the destructor.
Fixes #4922. Thanks to Victor Shugaev. Authorized by Rene.