summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-10-18 18:46:23 -0700
committerThiago Macieira <thiago.macieira@intel.com>2017-10-20 18:10:31 +0000
commit68092ba6c0f26f679c0a9c086e13e44557b76b11 (patch)
treed91cd3bf3033812925a0c6fb3969abbcca7baf10 /src/corelib
parent34c879f2e1c8a371ba5af664395d87aa878d0ed0 (diff)
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>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qrandom.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp
index a7696719d1..3ae7e3bad8 100644
--- a/src/corelib/global/qrandom.cpp
+++ b/src/corelib/global/qrandom.cpp
@@ -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)