Plugin install: Fix crash on cancel

When the process is aborted, both errorOccurred and then finished is
sent. Because of the combination of deleteLater and QueuedConnection
this leads to m_process being already nullptr when finished is sent, so
add some guards.

Change-Id: I446114176f8fa5934b411b39d77c97d6267303fa
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Eike Ziller
2020-06-23 08:34:35 +02:00
parent 611a3bb68a
commit 028c0b1cdd

View File

@@ -207,6 +207,8 @@ Archive *Archive::unarchive(const FilePath &src, const FilePath &dest)
&QProcess::readyReadStandardOutput,
archive,
[archive]() {
if (!archive->m_process)
return;
archive->outputReceived(QString::fromUtf8(archive->m_process->readAllStandardOutput()));
},
Qt::QueuedConnection);
@@ -215,6 +217,8 @@ Archive *Archive::unarchive(const FilePath &src, const FilePath &dest)
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
archive,
[archive](int, QProcess::ExitStatus) {
if (!archive->m_process)
return;
archive->finished(archive->m_process->exitStatus() == QProcess::NormalExit
&& archive->m_process->exitCode() == 0);
archive->m_process->deleteLater();
@@ -227,6 +231,8 @@ Archive *Archive::unarchive(const FilePath &src, const FilePath &dest)
&QProcess::errorOccurred,
archive,
[archive](QProcess::ProcessError) {
if (!archive->m_process)
return;
archive->outputReceived(tr("Command failed."));
archive->finished(false);
archive->m_process->deleteLater();