summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-11-08 14:05:41 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2021-11-08 22:39:45 +0100
commitac7e94090fdd0444cd56d46c0fed051481dada02 (patch)
tree07c5312f08013380d5525525653d52c0481a8ef3 /src/corelib
parent2010df52d4c805557255b90da4aaae8c54c443ea (diff)
qoperatingsystemversion_win: fix thread race
If two threads call the function at the same time before the static is initialized one of them may end up with a half-written object. Amends 3fe89eec61e2c819bb54a5d3dfe4bc29dba49ff3 Pick-to: 6.2 Change-Id: Ie08970f9ee283fd75292a8b44a1fca89de4b04eb Reviewed-by: Yuhang Zhao <2546789017@qq.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qoperatingsystemversion_win.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/global/qoperatingsystemversion_win.cpp b/src/corelib/global/qoperatingsystemversion_win.cpp
index e8c32be56b..c052cd9c9e 100644
--- a/src/corelib/global/qoperatingsystemversion_win.cpp
+++ b/src/corelib/global/qoperatingsystemversion_win.cpp
@@ -110,14 +110,15 @@ OSVERSIONINFOEX qWindowsVersionInfo()
QOperatingSystemVersion QOperatingSystemVersion::current()
{
- static QOperatingSystemVersion v;
- if (v.m_os == Unknown) {
+ static QOperatingSystemVersion v = [](){
+ QOperatingSystemVersion v;
v.m_os = currentType();
const OSVERSIONINFOEX osv = qWindowsVersionInfo();
v.m_major = osv.dwMajorVersion;
v.m_minor = osv.dwMinorVersion;
v.m_micro = osv.dwBuildNumber;
- }
+ return v;
+ }();
return v;
}