Fix crash on exit (restore cout/cerr rdbuf)