From 8fe717d8448c535ae9a715e6e216d226386beeee Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sun, 22 May 2022 23:17:11 +0800 Subject: [PATCH] fix: free resources in slots --- GPClient/gatewayauthenticator.cpp | 15 ++++++++++++--- GPClient/gpclient.cpp | 30 ++++++++++++++++++++++++------ GPClient/gpclient.h | 3 +++ GPClient/samlloginwindow.cpp | 1 + 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/GPClient/gatewayauthenticator.cpp b/GPClient/gatewayauthenticator.cpp index 37611ee..ed62984 100644 --- a/GPClient/gatewayauthenticator.cpp +++ b/GPClient/gatewayauthenticator.cpp @@ -162,9 +162,18 @@ void GatewayAuthenticator::samlAuth(QString samlMethod, QString samlRequest, QSt SAMLLoginWindow *loginWindow = new SAMLLoginWindow; - connect(loginWindow, &SAMLLoginWindow::success, this, &GatewayAuthenticator::onSAMLLoginSuccess); - connect(loginWindow, &SAMLLoginWindow::fail, this, &GatewayAuthenticator::onSAMLLoginFail); - connect(loginWindow, &SAMLLoginWindow::rejected, this, &GatewayAuthenticator::onLoginWindowRejected); + connect(loginWindow, &SAMLLoginWindow::success, [this, loginWindow](const QMap &samlResult) { + this->onSAMLLoginSuccess(samlResult); + loginWindow->deleteLater(); + }); + connect(loginWindow, &SAMLLoginWindow::fail, [this, loginWindow](const QString &error) { + this->onSAMLLoginFail(error); + loginWindow->deleteLater(); + }); + connect(loginWindow, &SAMLLoginWindow::rejected, [this, loginWindow]() { + this->onLoginWindowRejected(); + loginWindow->deleteLater(); + }); loginWindow->login(samlMethod, samlRequest, preloginUrl); } diff --git a/GPClient/gpclient.cpp b/GPClient/gpclient.cpp index 084410d..f65fa69 100644 --- a/GPClient/gpclient.cpp +++ b/GPClient/gpclient.cpp @@ -279,12 +279,24 @@ void GPClient::portalLogin() { PortalAuthenticator *portalAuth = new PortalAuthenticator(portal(), settings::get("clientos", "Linux").toString()); - connect(portalAuth, &PortalAuthenticator::success, this, &GPClient::onPortalSuccess); + connect(portalAuth, &PortalAuthenticator::success, [this, portalAuth](const PortalConfigResponse response, const QString region) { + this->onPortalSuccess(response, region); + portalAuth->deleteLater(); + }); // Prelogin failed on the portal interface, try to treat the portal as a gateway interface - connect(portalAuth, &PortalAuthenticator::preloginFailed, this, &GPClient::onPortalPreloginFail); - connect(portalAuth, &PortalAuthenticator::portalConfigFailed, this, &GPClient::onPortalConfigFail); + connect(portalAuth, &PortalAuthenticator::preloginFailed, [this, portalAuth](const QString msg) { + this->onPortalPreloginFail(msg); + portalAuth->deleteLater(); + }); + connect(portalAuth, &PortalAuthenticator::portalConfigFailed, [this, portalAuth](const QString msg) { + this->onPortalConfigFail(msg); + portalAuth->deleteLater(); + }); // Portal login failed - connect(portalAuth, &PortalAuthenticator::fail, this, &GPClient::onPortalFail); + connect(portalAuth, &PortalAuthenticator::fail, [this, portalAuth](const QString &msg) { + this->onPortalFail(msg); + portalAuth->deleteLater(); + }); ui->statusLabel->setText("Authenticating..."); updateConnectionStatus(VpnStatus::pending); @@ -359,8 +371,14 @@ void GPClient::gatewayLogin() GatewayAuthenticator *gatewayAuth = new GatewayAuthenticator(currentGateway().address(), params); - connect(gatewayAuth, &GatewayAuthenticator::success, this, &GPClient::onGatewaySuccess); - connect(gatewayAuth, &GatewayAuthenticator::fail, this, &GPClient::onGatewayFail); + connect(gatewayAuth, &GatewayAuthenticator::success, [this, gatewayAuth](const QString &authToken) { + this->onGatewaySuccess(authToken); + gatewayAuth->deleteLater(); + }); + connect(gatewayAuth, &GatewayAuthenticator::fail, [this, gatewayAuth](const QString &msg) { + this->onGatewayFail(msg); + gatewayAuth->deleteLater(); + }); ui->statusLabel->setText("Authenticating..."); updateConnectionStatus(VpnStatus::pending); diff --git a/GPClient/gpclient.h b/GPClient/gpclient.h index 0578305..051a0a2 100644 --- a/GPClient/gpclient.h +++ b/GPClient/gpclient.h @@ -9,6 +9,7 @@ #include "portalconfigresponse.h" #include "settingsdialog.h" #include "vpn.h" +#include "gatewayauthenticator.h" QT_BEGIN_NAMESPACE namespace Ui { class GPClient; } @@ -80,6 +81,8 @@ private: SettingsDialog *settingsDialog; QPushButton *settingsButton; + GatewayAuthenticator *gatewayAuthenticator; + bool isQuickConnect { false }; bool isSwitchingGateway { false }; PortalConfigResponse portalConfig; diff --git a/GPClient/samlloginwindow.cpp b/GPClient/samlloginwindow.cpp index e01682b..19c7b0d 100644 --- a/GPClient/samlloginwindow.cpp +++ b/GPClient/samlloginwindow.cpp @@ -15,6 +15,7 @@ SAMLLoginWindow::SAMLLoginWindow(QWidget *parent) QVBoxLayout *verticalLayout = new QVBoxLayout(this); webView->setUrl(QUrl("about:blank")); + webView->setAttribute(Qt::WA_DeleteOnClose); // webView->page()->profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); verticalLayout->addWidget(webView);