QRandomGenerator: fix the timing of the closing of the Unix random fd
Let's make it happen even later: at the time of QtCore's unloading from memory. This prevents issues with something using QRandomGenerator after the global static destructor would have run. Change-Id: Icaa86fc7b54d4b368c0efffd14eed56bbbb51cb6 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
This commit is contained in:
parent
34c879f2e1
commit
68092ba6c0
@ -152,15 +152,15 @@ class SystemRandom
|
||||
{
|
||||
static QBasicAtomicInt s_fdp1; // "file descriptor plus 1"
|
||||
static int openDevice();
|
||||
static __attribute__((destructor)) void closeDevice(); // assume GCC or a compiler able to understand GCC extensions
|
||||
SystemRandom() {}
|
||||
~SystemRandom();
|
||||
public:
|
||||
enum { EfficientBufferFill = true };
|
||||
static qssize_t fillBuffer(void *buffer, qssize_t count);
|
||||
};
|
||||
QBasicAtomicInt SystemRandom::s_fdp1 = Q_BASIC_ATOMIC_INITIALIZER(0);
|
||||
|
||||
SystemRandom::~SystemRandom()
|
||||
void SystemRandom::closeDevice()
|
||||
{
|
||||
int fd = s_fdp1.loadAcquire() - 1;
|
||||
if (fd >= 0)
|
||||
|
Loading…
Reference in New Issue
Block a user