From a24ec6b273892c41f1c163fd43b568e3e5ff8279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 31 Oct 2013 14:50:19 +0100 Subject: 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 Reviewed-by: Olivier Goffart --- src/corelib/tools/qlocale.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools/qlocale.cpp') 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, 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); -- cgit v1.2.3