From 958b9c80e1d54624228bad5fd3382a84bbce6553 Mon Sep 17 00:00:00 2001 From: Kai Liu Date: Mon, 22 Apr 2013 18:10:28 -0700 Subject: [PATCH] Avoid global static initialization in Env::Default() Summary: Mark's task description from #2316777 Env::Default() comes from util/env_posix.cc This is a static global. static PosixEnv default_env; Env* Env::Default() { return &default_env; } ----- These globals assume default_env was initialized first. I don't think that is safe or correct to do (http://stackoverflow.com/questions/1005685/c-static-initialization-order) const string AutoRollLoggerTest::kTestDir( test::TmpDir() + "/db_log_test"); const string AutoRollLoggerTest::kLogFile( test::TmpDir() + "/db_log_test/LOG"); Env* AutoRollLoggerTest::env = Env::Default(); Test Plan: run make clean && make && make check But how can I know if it works in Ubuntu? Reviewers: MarkCallaghan, chip Reviewed By: chip CC: leveldb, dhruba, haobo Differential Revision: https://reviews.facebook.net/D10491 --- util/env_posix.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/env_posix.cc b/util/env_posix.cc index a12709a2d..30e05d325 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -1078,9 +1078,8 @@ void PosixEnv::StartThread(void (*function)(void* arg), void* arg) { } // namespace -static PosixEnv default_env; - Env* Env::Default() { + static PosixEnv default_env; return &default_env; } -- GitLab