Move static global variable randomDevice inside the scope of the function
authorFrancis Ma <fma@fb.com>
Thu, 9 Oct 2014 15:35:06 +0000 (08:35 -0700)
committerAndrii Grynenko <andrii@fb.com>
Wed, 15 Oct 2014 00:56:51 +0000 (17:56 -0700)
Test Plan: Tests under folly passed

Reviewed By: seanc@fb.com

Subscribers: trunkagent, seanc, njormrod

FB internal diff: D1600266

Tasks: 5317470

folly/Random.cpp

index a189c3fc6789a2269f1a16fabd51a3995a129244..99a74f55081f27864ad22b9e7d825d42e8e30774 100644 (file)
@@ -30,10 +30,9 @@ namespace folly {
 
 namespace {
 
-// Keep it open for the duration of the program
-File randomDevice("/dev/urandom");
-
 void readRandomDevice(void* data, size_t size) {
+  // Keep it open for the duration of the program
+  static File randomDevice("/dev/urandom");
   PCHECK(readFull(randomDevice.fd(), data, size) == size);
 }