From 0700886b37806930e83e4707354b6797bd9d55ab Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Mon, 30 Jul 2018 14:24:47 +0200 Subject: [PATCH] guard localtime with a mutex to avoid race --- logger/Logger.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/logger/Logger.cxx b/logger/Logger.cxx index 113f3ab..d584dcd 100644 --- a/logger/Logger.cxx +++ b/logger/Logger.cxx @@ -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 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())