From 2d1805a378d481f8238d6b7ba316495901f298f8 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 23 Sep 2020 15:00:33 +0200 Subject: [PATCH] ProParser: Fix crash when starting a QProcess QProcess modifies the internals of its QProcessEnvironment object in a manner that is not thread-safe. We therefore force a detach, so each QProcess instance gets its own QProcessEnvironment. Fixes: QTCREATORBUG-23504 Change-Id: I7fc1fda5e7bc11ac4e9a59596a5bdb0ac420a315 Reviewed-by: Joerg Bornemann --- src/shared/proparser/qmakebuiltins.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/shared/proparser/qmakebuiltins.cpp b/src/shared/proparser/qmakebuiltins.cpp index bdd6ab6a6c8..b498ecdb473 100644 --- a/src/shared/proparser/qmakebuiltins.cpp +++ b/src/shared/proparser/qmakebuiltins.cpp @@ -459,8 +459,18 @@ void QMakeEvaluator::runProcess(QProcess *proc, const QString &command) const { proc->setWorkingDirectory(currentDirectory()); # ifdef PROEVALUATOR_SETENV - if (!m_option->environment.isEmpty()) - proc->setProcessEnvironment(m_option->environment); + if (!m_option->environment.isEmpty()) { + QProcessEnvironment env = m_option->environment; + static const QString dummyVar = "__qtc_dummy"; + static const QString notSetValue = "not set"; + const QString oldValue = env.value(dummyVar, notSetValue); // Just in case. + env.insert(dummyVar, "QTCREATORBUG-23504"); // Force detach. + if (oldValue == notSetValue) + env.remove(dummyVar); + else + env.insert(dummyVar, oldValue); + proc->setProcessEnvironment(env); + } # endif # ifdef Q_OS_WIN proc->setNativeArguments(QLatin1String("/v:off /s /c \"") + command + QLatin1Char('"'));