summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qsettings.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-24 10:47:29 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-30 14:21:46 +0000
commit8272f5415b1ac89fd169513160870ab85bbf1bef (patch)
tree41a7337c7e24f319a99ed0785b080cc5d0e67671 /src/corelib/io/qsettings.cpp
parent4b9cf0379ff320dd77b7957ad1865187a8bc3562 (diff)
Fix crashes when accessing environment variables concurrently
We've seen crashes with QThreadPrivate::start using qgetenv during the creation of the event dispatcher, while another thread (for example the gui thread) called qputenv. This is inherently thread-unsafe and there are many places where we make the assumption that using the environment is safe. However access to the environment is inherently unsafe in the C runtime and the best that we can do is add a mutex around the Qt environment access functions, to at least protect ourselves and our users. Change-Id: Ie9a718d9f7ce63c423c645f0be3e3f4933e1cb08 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Diffstat (limited to 'src/corelib/io/qsettings.cpp')
-rw-r--r--src/corelib/io/qsettings.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp
index afe68125d4..cb6de29532 100644
--- a/src/corelib/io/qsettings.cpp
+++ b/src/corelib/io/qsettings.cpp
@@ -1048,12 +1048,12 @@ static void initDefaultPaths(QMutexLocker *locker)
// Non XDG platforms (OS X, iOS, Blackberry, Android...) have used this code path erroneously
// for some time now. Moving away from that would require migrating existing settings.
QString userPath;
- char *env = getenv("XDG_CONFIG_HOME");
- if (env == 0) {
+ QByteArray env = qgetenv("XDG_CONFIG_HOME");
+ if (env.isEmpty()) {
userPath = QDir::homePath();
userPath += QLatin1Char('/');
userPath += QLatin1String(".config");
- } else if (*env == '/') {
+ } else if (env.startsWith('/')) {
userPath = QFile::decodeName(env);
} else {
userPath = QDir::homePath();