guard localtime with a mutex to avoid race

This commit is contained in:
Alexey Rybalchenko 2018-07-30 14:24:47 +02:00
parent 63820e5f2c
commit 0700886b37

View File

@ -575,10 +575,13 @@ void Logger::RemoveCustomSink(const string& key)
Logger& Logger::Log() Logger& Logger::Log()
{ {
char tsstr[32]; char tsstr[32];
{
lock_guard<mutex> lock(fMtx); // localtime is not threadsafe, guard it
if (!strftime(tsstr, sizeof(tsstr), "%H:%M:%S", localtime(&(fMetaData.timestamp)))) if (!strftime(tsstr, sizeof(tsstr), "%H:%M:%S", localtime(&(fMetaData.timestamp))))
{ {
tsstr[0] = 'u'; tsstr[0] = 'u';
} }
}
if ((!fColored && LoggingToConsole()) || LoggingToFile()) if ((!fColored && LoggingToConsole()) || LoggingToFile())
{ {