aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Utilities/Util.cpp
diff options
context:
space:
mode:
authorjackpoz <giacomopoz@gmail.com>2013-09-07 14:37:54 +0200
committerjackpoz <giacomopoz@gmail.com>2013-09-07 14:37:54 +0200
commit9578b5f87a4aa96e120b78f410ea90e141903dd7 (patch)
treed3aa8e7d88004d03342e355c8c6d3cf43f6eddb1 /src/server/shared/Utilities/Util.cpp
parent8c70f8cb08d2fc3b38abcac25d421cdd92e25615 (diff)
Core/Thread: Fix race condition converting time values to local time
Replace thread-unsafe localtime() http://www.cplusplus.com/reference/ctime/localtime/ with thread-safe portable ACE_OS::localtime_r() . Helgrind log: Possible data race during read of size 4 at 0x6F183C0 by thread #1 Locks held: none at 0x14E72E3: World::InitDailyQuestResetTime() (World.cpp:2772) by 0x14E3A01: World::SetInitialWorldSettings() (World.cpp:1790) by 0x101122A: Master::Run() (Master.cpp:164) by 0x101740C: main (Main.cpp:142) This conflicts with a previous write of size 4 by thread #2 Locks held: none at 0x6C2D3BA: __tzfile_compute (tzfile.c:797) by 0x6C2D036: __tz_convert (tzset.c:627) by 0x164146C: LogMessage::getTimeStr(long) (Appender.cpp:23) by 0x1641550: LogMessage::getTimeStr() (Appender.cpp:31) by 0x1641722: Appender::write(LogMessage&) (Appender.cpp:80) by 0x1633FCE: Logger::write(LogMessage&) (Logger.cpp:83) by 0x16433D8: LogOperation::call() (LogOperation.cpp:29) by 0x16428A4: LogWorker::svc() (LogWorker.cpp:45)
Diffstat (limited to 'src/server/shared/Utilities/Util.cpp')
-rw-r--r--src/server/shared/Utilities/Util.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
index 1bba3c2db09..48012b6eea8 100644
--- a/src/server/shared/Utilities/Util.cpp
+++ b/src/server/shared/Utilities/Util.cpp
@@ -215,7 +215,8 @@ uint32 TimeStringToSecs(const std::string& timestring)
std::string TimeToTimestampStr(time_t t)
{
- tm* aTm = localtime(&t);
+ tm aTm;
+ ACE_OS::localtime_r(&t, &aTm);
// YYYY year
// MM month (2 digits 01-12)
// DD day (2 digits 01-31)
@@ -223,7 +224,7 @@ std::string TimeToTimestampStr(time_t t)
// MM minutes (2 digits 00-59)
// SS seconds (2 digits 00-59)
char buf[20];
- snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm->tm_year+1900, aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec);
+ snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
return std::string(buf);
}