fix stdout redirection crash on exit for Mac