aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-12-01 11:47:39 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2016-12-01 11:47:47 +0100
commitc79e52ad304a02cb66c66cfee49c9b82b458e769 (patch)
treea663bd9df23c6ca75fc6abe0f12da712929ddc7a
parent3bf06e9bac57b5b5a746677b75e297a7b154bdbd (diff)
parent8b22efb6f7c406951f33a04e84377fd16f02121c (diff)
downloadbitcoin-c79e52ad304a02cb66c66cfee49c9b82b458e769.tar.xz
Merge #9230: Fix some benign races in timestamp logging
8b22efb Make fStartedNewLine an std::atomic_bool (Matt Corallo) 507145d Fix race when accessing std::locale::classic() (Matt Corallo)
-rw-r--r--src/util.cpp4
-rw-r--r--src/utiltime.cpp3
2 files changed, 4 insertions, 3 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 332e077627..014013d214 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -258,7 +258,7 @@ bool LogAcceptCategory(const char* category)
* suppress printing of the timestamp when multiple calls are made that don't
* end in a newline. Initialize it to true, and hold it, in the calling context.
*/
-static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine)
+static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fStartedNewLine)
{
string strStamped;
@@ -285,7 +285,7 @@ static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine
int LogPrintStr(const std::string &str)
{
int ret = 0; // Returns total number of characters written
- static bool fStartedNewLine = true;
+ static std::atomic_bool fStartedNewLine(true);
string strTimestamped = LogTimestampStr(str, &fStartedNewLine);
diff --git a/src/utiltime.cpp b/src/utiltime.cpp
index da590f8889..51d545ef8a 100644
--- a/src/utiltime.cpp
+++ b/src/utiltime.cpp
@@ -74,8 +74,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);