From ebae255e49cd2c5411f6948417e0d927dd020525 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 3 Sep 2021 09:29:33 +0200 Subject: [PATCH] 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 --- src/plugins/cmakeprojectmanager/cmakeprocess.cpp | 4 +--- src/plugins/coreplugin/reaper.cpp | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeprocess.cpp b/src/plugins/cmakeprojectmanager/cmakeprocess.cpp index ae39d5f9182..45c820974a4 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprocess.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprocess.cpp @@ -57,10 +57,8 @@ CMakeProcess::CMakeProcess() CMakeProcess::~CMakeProcess() { - if (m_process) { - m_process->disconnect(); + if (m_process) Core::Reaper::reap(m_process.release()); - } m_parser.flush(); diff --git a/src/plugins/coreplugin/reaper.cpp b/src/plugins/coreplugin/reaper.cpp index fa8408abb17..c10c460e62c 100644 --- a/src/plugins/coreplugin/reaper.cpp +++ b/src/plugins/coreplugin/reaper.cpp @@ -157,6 +157,10 @@ void reap(QtcProcess *process, int timeoutMs) if (!process) return; + process->setStdOutCallback(nullptr); + process->setStdErrCallback(nullptr); + process->disconnect(); + QTC_ASSERT(Internal::d, return); new Internal::ProcessReaper(process, timeoutMs);