diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2019-01-30 21:13:51 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2019-02-01 20:53:34 +0000 |
commit | 188eea0eb47c499f70a60f573948d529089d93b1 (patch) | |
tree | 7c37e96b0505f31d3eb29a8e8f3d96813a6a5a7c /src | |
parent | d84912838c1df383d2a9537aefa34e06a9780f08 (diff) |
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 <thomas@sondergaard.cc>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 4 |
1 files 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<QLocalePrivate>, defaultLocalePrivate, (QLocalePrivate::create(defaultData(), default_number_options))) -Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, systemLocalePrivate, +Q_GLOBAL_STATIC_WITH_ARGS(QExplicitlySharedDataPointer<QLocalePrivate>, systemLocalePrivate, (QLocalePrivate::create(systemData()))) static QLocalePrivate *localePrivateByName(const QString &name) |