Fix a possible crash when reaping a process with callbacks

It may happen that CMakeProcess destructor puts its internal
process into the reaper. After this, when the CMakeProcess
is already destructed, the internal process may still be working.
Since we have set the StdErrLineCallback lambda for the process
which accesses the private m_parser field, it may potentially
crash.

Solve it in a general way, so that whenever we put a process
to the reaper we reset its callbacks.

In addition, disconnect all the slots connected to process'
signals.

Fixes: QTCREATORBUG-26220
Change-Id: I63ea0e0ed6a62ef97ac695572f18014458489c5c
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Jarek Kobus
2021-09-03 09:29:33 +02:00
committed by Cristian Adam
parent 4772253d9d
commit ebae255e49
2 changed files with 5 additions and 3 deletions

View File

@@ -57,10 +57,8 @@ CMakeProcess::CMakeProcess()
CMakeProcess::~CMakeProcess() CMakeProcess::~CMakeProcess()
{ {
if (m_process) { if (m_process)
m_process->disconnect();
Core::Reaper::reap(m_process.release()); Core::Reaper::reap(m_process.release());
}
m_parser.flush(); m_parser.flush();

View File

@@ -157,6 +157,10 @@ void reap(QtcProcess *process, int timeoutMs)
if (!process) if (!process)
return; return;
process->setStdOutCallback(nullptr);
process->setStdErrCallback(nullptr);
process->disconnect();
QTC_ASSERT(Internal::d, return); QTC_ASSERT(Internal::d, return);
new Internal::ProcessReaper(process, timeoutMs); new Internal::ProcessReaper(process, timeoutMs);