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 <joerg.bornemann@qt.io>
This commit is contained in:
Christian Kandeler
2020-09-23 15:00:33 +02:00
parent 4b8635052f
commit 2d1805a378

View File

@@ -459,8 +459,18 @@ void QMakeEvaluator::runProcess(QProcess *proc, const QString &command) const
{ {
proc->setWorkingDirectory(currentDirectory()); proc->setWorkingDirectory(currentDirectory());
# ifdef PROEVALUATOR_SETENV # ifdef PROEVALUATOR_SETENV
if (!m_option->environment.isEmpty()) if (!m_option->environment.isEmpty()) {
proc->setProcessEnvironment(m_option->environment); 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 # endif
# ifdef Q_OS_WIN # ifdef Q_OS_WIN
proc->setNativeArguments(QLatin1String("/v:off /s /c \"") + command + QLatin1Char('"')); proc->setNativeArguments(QLatin1String("/v:off /s /c \"") + command + QLatin1Char('"'));