Bump version to 47:0
[folly.git] / folly / Random.cpp
index 4ed578c31dd8266588ed30b155a6512b7eb27c57..87da68b6b5216469591efd17ad68466fd1c00068 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,10 +31,10 @@ namespace folly {
 namespace {
 
 void readRandomDevice(void* data, size_t size) {
-  // Keep it open for the duration of the program. Note that we leak the File
-  // to ensure the file is indeed open for the duration of the program.
-  static File& randomDevice = *new File("/dev/urandom");
-  auto bytesRead = readFull(randomDevice.fd(), data, size);
+  // Keep the random device open for the duration of the program.
+  static int randomFd = ::open("/dev/urandom", O_RDONLY);
+  PCHECK(randomFd >= 0);
+  auto bytesRead = readFull(randomFd, data, size);
   PCHECK(bytesRead >= 0 && size_t(bytesRead) == size);
 }