From df767f1c48a3e89fb55e37fa499bff291ae22804 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 6 May 2013 21:53:17 +0300 Subject: [PATCH] Git: Fix leak when GerritPushDialog is canceled or fails Change-Id: Id7479f44ee01f68e1423cc8346bc80f78ddfedb4 Reviewed-by: Petar Perisin Reviewed-by: Tobias Hunger --- src/plugins/git/gerrit/gerritplugin.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp index 80f5f56d141..040df732724 100644 --- a/src/plugins/git/gerrit/gerritplugin.cpp +++ b/src/plugins/git/gerrit/gerritplugin.cpp @@ -363,7 +363,9 @@ void GerritPlugin::push() { const QString topLevel = Git::Internal::GitPlugin::instance()->currentState().topLevel(); - QPointer dialog = new GerritPushDialog(topLevel, Core::ICore::mainWindow()); + // QScopedPointer is required to delete the dialog when leaving the function + QScopedPointer dialog( + new GerritPushDialog(topLevel, Core::ICore::mainWindow())); if (!dialog->localChangesFound()) { QMessageBox::warning(Core::ICore::mainWindow(), tr("No Local Changes"), @@ -377,11 +379,15 @@ void GerritPlugin::push() return; } + // QPointer is required to detect dialog deletion while in exec() + QPointer dlg = dialog.data(); if (dialog->exec() == QDialog::Rejected) return; - if (dialog.isNull()) + if (dlg.isNull()) { + dialog.take(); return; + } QStringList args; @@ -406,8 +412,6 @@ void GerritPlugin::push() args << target; Git::Internal::GitPlugin::instance()->gitClient()->synchronousPush(topLevel, args); - - delete dialog; } // Open or raise the Gerrit dialog window.