diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2013-10-31 14:50:19 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-04 11:42:01 +0100 |
commit | a24ec6b273892c41f1c163fd43b568e3e5ff8279 (patch) | |
tree | 1953975cd949eee4770fc4aa8e91eec3191ceae3 /src/corelib/tools/qlocale.cpp | |
parent | 7b2ae0db664a5f3fe9982a409e7e493245dde8ba (diff) |
Ensure QLocale's shared C-locale QLocalePrivate is never deleted
Other static data such as QTextStream might be initialized before the
static C-locale, in which case QLocale would adopt c_private and bump
the ref-count to 2, only to see it reset back to 1 when the c_locale's
static initialization happened.
The result was that at application shutdown the ref-count would fall
down to 0, and we tried deleting the static data.
This issue was observed with clang in a debug build, where the c_private
is initialized at runtime.
Change-Id: If05221a5e87886e1805ad3c1b1520483f425c0fb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index fb233c0640..0eb202c5e2 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -531,7 +531,11 @@ static const QLocaleData *default_data = 0; static uint default_number_options = 0; static const QLocaleData *const c_data = locale_data; -static QLocalePrivate c_private = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), 0 }; +static QLocalePrivate *c_private() +{ + static QLocalePrivate c_locale = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), 0 }; + return &c_locale; +} #ifndef QT_NO_SYSTEMLOCALE @@ -700,7 +704,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, defaultLocalePriva static QLocalePrivate *localePrivateByName(const QString &name) { if (name == QLatin1String("C")) - return &c_private; + return c_private(); return QLocalePrivate::create(findLocaleData(name)); } @@ -708,7 +712,7 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc QLocale::Country country) { if (language == QLocale::C) - return &c_private; + return c_private(); const QLocaleData *data = QLocaleData::findLocaleData(language, script, country); |