VcsBase, Git: Don't use queued connections to VcsCommand

Otherwise, the destructor of VcsCommand could have been
executed in meantime (since it's invoked automatically
after done()) and we might access invalid pointer to the
command inside the done handler.

Change-Id: I031e2281952451d4e01c47f437097a1e7bf8899f
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-12-08 14:43:50 +01:00
parent 533d969735
commit a6b17d127a
2 changed files with 7 additions and 8 deletions

View File

@@ -1108,8 +1108,8 @@ void GitClient::status(const FilePath &workingDirectory) const
{ {
VcsOutputWindow::setRepository(workingDirectory); VcsOutputWindow::setRepository(workingDirectory);
VcsCommand *command = vcsExec(workingDirectory, {"status", "-u"}, nullptr, true); VcsCommand *command = vcsExec(workingDirectory, {"status", "-u"}, nullptr, true);
connect(command, &VcsCommand::done, VcsOutputWindow::instance(), connect(command, &VcsCommand::done,
&VcsOutputWindow::clearRepository, Qt::QueuedConnection); VcsOutputWindow::instance(), &VcsOutputWindow::clearRepository);
} }
static QStringList normalLogArguments() static QStringList normalLogArguments()
@@ -3113,7 +3113,7 @@ void GitClient::pull(const FilePath &workingDirectory, bool rebase)
connect(command, &VcsCommand::done, this, [this, workingDirectory, command] { connect(command, &VcsCommand::done, this, [this, workingDirectory, command] {
if (command->result() == ProcessResult::FinishedWithSuccess) if (command->result() == ProcessResult::FinishedWithSuccess)
updateSubmodulesIfNeeded(workingDirectory, true); updateSubmodulesIfNeeded(workingDirectory, true);
}, Qt::QueuedConnection); });
} }
void GitClient::synchronousAbortCommand(const FilePath &workingDir, const QString &abortCommand) void GitClient::synchronousAbortCommand(const FilePath &workingDir, const QString &abortCommand)

View File

@@ -420,7 +420,7 @@ void VcsBaseClient::revertFile(const FilePath &workingDir,
connect(cmd, &VcsCommand::done, this, [this, files, cmd] { connect(cmd, &VcsCommand::done, this, [this, files, cmd] {
if (cmd->result() == ProcessResult::FinishedWithSuccess) if (cmd->result() == ProcessResult::FinishedWithSuccess)
emit changed(files); emit changed(files);
}, Qt::QueuedConnection); });
enqueueJob(cmd, args); enqueueJob(cmd, args);
} }
@@ -436,7 +436,7 @@ void VcsBaseClient::revertAll(const FilePath &workingDir,
connect(cmd, &VcsCommand::done, this, [this, files, cmd] { connect(cmd, &VcsCommand::done, this, [this, files, cmd] {
if (cmd->result() == ProcessResult::FinishedWithSuccess) if (cmd->result() == ProcessResult::FinishedWithSuccess)
emit changed(files); emit changed(files);
}, Qt::QueuedConnection); });
enqueueJob(createCommand(workingDir), args); enqueueJob(createCommand(workingDir), args);
} }
@@ -448,8 +448,7 @@ void VcsBaseClient::status(const FilePath &workingDir,
args << extraOptions << file; args << extraOptions << file;
VcsOutputWindow::setRepository(workingDir); VcsOutputWindow::setRepository(workingDir);
VcsCommand *cmd = createCommand(workingDir, nullptr, VcsWindowOutputBind); VcsCommand *cmd = createCommand(workingDir, nullptr, VcsWindowOutputBind);
connect(cmd, &VcsCommand::done, VcsOutputWindow::instance(), &VcsOutputWindow::clearRepository, connect(cmd, &VcsCommand::done, VcsOutputWindow::instance(), &VcsOutputWindow::clearRepository);
Qt::QueuedConnection);
enqueueJob(cmd, args); enqueueJob(cmd, args);
} }
@@ -535,7 +534,7 @@ void VcsBaseClient::update(const FilePath &repositoryRoot, const QString &revisi
connect(cmd, &VcsCommand::done, this, [this, repositoryRoot, cmd] { connect(cmd, &VcsCommand::done, this, [this, repositoryRoot, cmd] {
if (cmd->result() == ProcessResult::FinishedWithSuccess) if (cmd->result() == ProcessResult::FinishedWithSuccess)
emit changed(repositoryRoot.toString()); emit changed(repositoryRoot.toString());
}, Qt::QueuedConnection); });
enqueueJob(cmd, args); enqueueJob(cmd, args);
} }