From ac7e94090fdd0444cd56d46c0fed051481dada02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 8 Nov 2021 14:05:41 +0100 Subject: 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 --- src/corelib/global/qoperatingsystemversion_win.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/corelib') 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; } -- cgit v1.2.3