From 188eea0eb47c499f70a60f573948d529089d93b1 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 30 Jan 2019 21:13:51 -0800 Subject: [PATCH] Fix race condition in getting the system locale data QSharedDataPointer obeys the regular Qt container thread-safety rules: it's thread-safe in const methods but not in mutating ones. QSDP::data() is mutating, which causes a data race. For example, if the contained QLocalePrivate has a refcount of 2 and two threads see that, both threads will try to detach and then replace the pointer, but that pointer replacement is not atomic. Using QExplicitSharedDataPointer makes the race go away, since data() is now non-mutating. QESDP is used only to destroy the QLocalePrivate on program shutdown. Note that there are still race conditions relating to *updating* the locale private. Fixes: QTBUG-73403 Change-Id: Id98140e1c2f0426cabbefffd157ed6ec30a3e08f Reviewed-by: Thomas Sondergaard Reviewed-by: Edward Welbourne --- src/corelib/tools/qlocale.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 63499ab93f..df768fb875 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. +** Copyright (C) 2019 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -781,7 +781,7 @@ static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1; Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer, defaultLocalePrivate, (QLocalePrivate::create(defaultData(), default_number_options))) -Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer, systemLocalePrivate, +Q_GLOBAL_STATIC_WITH_ARGS(QExplicitlySharedDataPointer, systemLocalePrivate, (QLocalePrivate::create(systemData()))) static QLocalePrivate *localePrivateByName(const QString &name)