guard localtime with a mutex to avoid race

This commit is contained in:
Alexey Rybalchenko 2018-07-30 14:24:47 +02:00 committed by Dennis Klein
parent 63820e5f2c
commit 1f600fa981

View File

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