From e23e5faa82c9445a513d7803c97dc08c6a407495 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 20 Oct 2022 15:42:59 +0200 Subject: [PATCH] Environment: Make systemEnvironment() thread safe Fixes: QTCREATORBUG-26805 Change-Id: I839995699ffd25579a6a77405331a9802edaf7f1 Reviewed-by: Eike Ziller --- src/libs/utils/environment.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp index 62dc52b2605..05c5e05e5ae 100644 --- a/src/libs/utils/environment.cpp +++ b/src/libs/utils/environment.cpp @@ -4,18 +4,18 @@ #include "environment.h" #include "algorithm.h" -#include "fileutils.h" #include "qtcassert.h" #include #include +#include #include namespace Utils { +static QReadWriteLock s_envMutex; Q_GLOBAL_STATIC_WITH_ARGS(Environment, staticSystemEnvironment, (QProcessEnvironment::systemEnvironment().toStringList())) - Q_GLOBAL_STATIC(QVector, environmentProviders) NameValueItems Environment::diff(const Environment &other, bool checkAppendPrepend) const @@ -120,6 +120,7 @@ void Environment::prependOrSetLibrarySearchPaths(const FilePaths &values) Environment Environment::systemEnvironment() { + QReadLocker lock(&s_envMutex); return *staticSystemEnvironment(); } @@ -296,11 +297,13 @@ FilePaths Environment::pathListValue(const QString &varName) const void Environment::modifySystemEnvironment(const EnvironmentItems &list) { + QWriteLocker lock(&s_envMutex); staticSystemEnvironment->modify(list); } void Environment::setSystemEnvironment(const Environment &environment) { + QWriteLocker lock(&s_envMutex); *staticSystemEnvironment = environment; }