Fix SignalHandlerTest with ASAN
[folly.git] / folly / experimental / TestUtil.cpp
index f13b9208a4a31e826ac88e34d1056423d9de302a..987d605b3bb1483a4aa5d021516f8add7d01f695 100644 (file)
@@ -129,14 +129,15 @@ TemporaryDirectory::~TemporaryDirectory() {
   }
 }
 
-ChangeToTempDir::ChangeToTempDir() : initialPath_(fs::current_path()) {
-  std::string p = dir_.path().string();
-  ::chdir(p.c_str());
+ChangeToTempDir::ChangeToTempDir() {
+  orig_ = fs::current_path();
+  fs::current_path(path());
 }
 
 ChangeToTempDir::~ChangeToTempDir() {
-  std::string p = initialPath_.string();
-  ::chdir(p.c_str());
+  if (!orig_.empty()) {
+    fs::current_path(orig_);
+  }
 }
 
 namespace detail {