From 29f262e514dbc0558723cfd0e75746c554419c3d Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 28 Sep 2019 11:16:14 +0200 Subject: [PATCH] Fix crash on destructed stream usage --- components/debug/debugging.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/debug/debugging.cpp b/components/debug/debugging.cpp index 28446ccc78..dfed077e37 100644 --- a/components/debug/debugging.cpp +++ b/components/debug/debugging.cpp @@ -97,9 +97,13 @@ int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, c std::streambuf* cout_rdbuf = std::cout.rdbuf (); std::streambuf* cerr_rdbuf = std::cerr.rdbuf (); -#if !(defined(_WIN32) && defined(_DEBUG)) +#if defined(_WIN32) && defined(_DEBUG) + boost::iostreams::stream_buffer sb; +#else boost::iostreams::stream_buffer coutsb; boost::iostreams::stream_buffer cerrsb; + std::ostream oldcout(cout_rdbuf); + std::ostream oldcerr(cerr_rdbuf); #endif const std::string logName = Misc::StringUtils::lowerCase(appName) + ".log"; @@ -113,7 +117,6 @@ int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, c #if defined(_WIN32) && defined(_DEBUG) // Redirect cout and cerr to VS debug output when running in debug mode - boost::iostreams::stream_buffer sb; sb.open(Debug::DebugOutput()); std::cout.rdbuf (&sb); std::cerr.rdbuf (&sb); @@ -121,8 +124,6 @@ int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, c // Redirect cout and cerr to the log file logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / logName)); - std::ostream oldcout(cout_rdbuf); - std::ostream oldcerr(cerr_rdbuf); coutsb.open (Debug::Tee(logfile, oldcout)); cerrsb.open (Debug::Tee(logfile, oldcerr));