Fix race when accessing std::locale::classic()

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78552

zcash: cherry picked from commit 507145d78595e052ce13368e122f72c85093992c
zcash: https://github.com/bitcoin/bitcoin/pull/9230
This commit is contained in:
Matt Corallo 2016-11-27 15:11:49 -08:00 committed by Larry Ruane
parent 451600b9a6
commit cafc3f845d
1 changed files with 2 additions and 1 deletions

View File

@ -50,8 +50,9 @@ void MilliSleep(int64_t n)
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
{
static std::locale classic(std::locale::classic());
// std::locale takes ownership of the pointer
std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat));
std::locale loc(classic, new boost::posix_time::time_facet(pszFormat));
std::stringstream ss;
ss.imbue(loc);
ss << boost::posix_time::from_time_t(nTime);