From 2770a94c4281643c92a785a0dd711013920c2d35 Mon Sep 17 00:00:00 2001 From: Zhongyi Xie Date: Tue, 10 Apr 2018 14:04:44 -0700 Subject: [PATCH] make MockTimeEnv::current_time_ atomic to fix data race Summary: fix a new TSAN failure https://gist.github.com/miasantreble/7599c33f4e17da1024c67d4540dbe397 Closes https://github.com/facebook/rocksdb/pull/3694 Differential Revision: D7565310 Pulled By: miasantreble fbshipit-source-id: f672c96e925797b34dec6e20b59527e8eebaa825 --- db/db_test_util.h | 2 +- util/status.cc | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/db/db_test_util.h b/db/db_test_util.h index df1e7cfb2d..f9d1eca3f5 100644 --- a/db/db_test_util.h +++ b/db/db_test_util.h @@ -606,7 +606,7 @@ class MockTimeEnv : public EnvWrapper { } private: - uint64_t current_time_ = 0; + std::atomic current_time_{0}; }; #ifndef ROCKSDB_LITE diff --git a/util/status.cc b/util/status.cc index 1881c58de0..319b0d9a4e 100644 --- a/util/status.cc +++ b/util/status.cc @@ -15,10 +15,11 @@ namespace rocksdb { const char* Status::CopyState(const char* state) { - const size_t cch = + const size_t cch = std::strlen(state) + 1; // +1 for the null terminator char* const result = - new char[cch]; + new char[cch]; + result[cch - 1] = '\0'; #ifdef OS_WIN errno_t ret; ret = strncpy_s(result, cch, state, cch - 1);