Commit 35654c7b authored by Brian Watling's avatar Brian Watling Committed by Pavlo Kushnir

Remove memory leak from readRandomDevice by using a raw fd

Summary: Switch from dynamically allocating a File to using a raw fd for readRandomDevice. This prevents races at shutdown while also eliminating the memory leak

Test Plan: run unit tests

Reviewed By: meyering@fb.com

Subscribers: njormrod, folly-diffs@, tao-eng@

FB internal diff: D1662151

Signature: t1:1662151:1415229242:525b6294b27bb68b5dda70aadb8d3ba1cc61b815
parent 100ebad7
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment