MesonProcess: Fix process restart

It looks like MesonProjectParser::m_process may be restarted
directly from process' finished() handler - inside
MesonProjectParser::processFinished(). In this case
the process is directly deleted from its signal handler.
Fix it by releasing the old process and deleting it later.

Don't pass process reference to the other thread when
calling runAsync(). Pass the copy of standard output instead.

Change-Id: I163a3cc86fbdbe8a3d9a19c479f96017f5803f76
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-10-12 08:26:39 +02:00
parent 6c362a259c
commit c97cb8b50c
2 changed files with 11 additions and 11 deletions

View File

@@ -85,6 +85,8 @@ void MesonProcess::setupProcess(const Command &command,
const Environment env, const Environment env,
bool captureStdo) bool captureStdo)
{ {
if (m_process)
m_process.release()->deleteLater();
m_process.reset(new QtcProcess); m_process.reset(new QtcProcess);
connect(m_process.get(), &QtcProcess::done, this, &MesonProcess::handleProcessDone); connect(m_process.get(), &QtcProcess::done, this, &MesonProcess::handleProcessDone);
if (!captureStdo) { if (!captureStdo) {

View File

@@ -196,20 +196,18 @@ QList<ProjectExplorer::BuildTargetInfo> MesonProjectParser::appsTargets() const
} }
return apps; return apps;
} }
bool MesonProjectParser::startParser() bool MesonProjectParser::startParser()
{ {
m_parserFutureResult = Utils::runAsync( m_parserFutureResult = Utils::runAsync(
ProjectExplorer::ProjectExplorerPlugin::sharedThreadPool(), ProjectExplorer::ProjectExplorerPlugin::sharedThreadPool(),
[process = &m_process, [processOutput = m_process.stdOut(), introType = m_introType,
introType = m_introType, buildDir = m_buildDir.toString(), srcDir = m_srcDir] {
buildDir = m_buildDir.toString(), if (introType == IntroDataType::file)
srcDir = m_srcDir]() { return extractParserResults(srcDir, MesonInfoParser::parse(buildDir));
if (introType == IntroDataType::file) { else
return extractParserResults(srcDir, MesonInfoParser::parse(buildDir)); return extractParserResults(srcDir, MesonInfoParser::parse(processOutput));
} else { });
return extractParserResults(srcDir, MesonInfoParser::parse(process->stdOut()));
}
});
Utils::onFinished(m_parserFutureResult, this, &MesonProjectParser::update); Utils::onFinished(m_parserFutureResult, this, &MesonProjectParser::update);
return true; return true;