forked from qt-creator/qt-creator
Fix a possible crash in process launcher
It may apparently happen that when calling QProcess::start() we may receive a synchronous signal QProcess::errorOccurred() from the process we are trying to start. In this case the handler of the error signal might have removed the process from m_processes hash, which invalidated the "Process *& process" reference inside LauncherSocketHandler::handleStartPacket(). So, using process reference after calling start() may be dangerous. Refactor ProcessStartHandler so that it stores the pointer to the process it handles. The pointer to the handler should still be valid after calling start(), since the process itself is being deleted with a delay. Make ProcessStartHandler a member of ProcessHelper. In this way it's being reused in QProcessImpl and ProcessLauncher. Fixes: QTCREATORBUG-26726 Change-Id: I8e3f39953035d76c83bbbb13bd78e3042ba2a14e Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -314,17 +314,18 @@ public:
|
||||
{ m_process->setWorkingDirectory(dir); }
|
||||
void start(const QString &program, const QStringList &arguments, const QByteArray &writeData) override
|
||||
{
|
||||
m_processStartHandler.setProcessMode(processMode());
|
||||
m_processStartHandler.setWriteData(writeData);
|
||||
ProcessStartHandler *handler = m_process->processStartHandler();
|
||||
handler->setProcessMode(processMode());
|
||||
handler->setWriteData(writeData);
|
||||
if (isBelowNormalPriority())
|
||||
m_processStartHandler.setBelowNormalPriority(m_process);
|
||||
m_processStartHandler.setNativeArguments(m_process, nativeArguments());
|
||||
handler->setBelowNormalPriority();
|
||||
handler->setNativeArguments(nativeArguments());
|
||||
if (isLowPriority())
|
||||
m_process->setLowPriority();
|
||||
if (isUnixTerminalDisabled())
|
||||
m_process->setUnixTerminalDisabled();
|
||||
m_process->start(program, arguments, m_processStartHandler.openMode());
|
||||
m_processStartHandler.handleProcessStart(m_process);
|
||||
m_process->start(program, arguments, handler->openMode());
|
||||
handler->handleProcessStart();
|
||||
}
|
||||
void terminate() override
|
||||
{ m_process->terminate(); }
|
||||
@@ -367,11 +368,10 @@ public:
|
||||
private:
|
||||
void handleStarted()
|
||||
{
|
||||
m_processStartHandler.handleProcessStarted(m_process);
|
||||
m_process->processStartHandler()->handleProcessStarted();
|
||||
emit started();
|
||||
}
|
||||
ProcessHelper *m_process;
|
||||
ProcessStartHandler m_processStartHandler;
|
||||
};
|
||||
|
||||
static uint uniqueToken()
|
||||
|
||||
Reference in New Issue
Block a user