Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure _profile and _page are deleted in the correct order #959

Merged
merged 1 commit into from Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/gui/creds/webflowcredentialsdialog.cpp
Expand Up @@ -29,6 +29,14 @@ WebFlowCredentialsDialog::WebFlowCredentialsDialog(QWidget *parent)
connect(_webView, &WebView::urlCatched, this, &WebFlowCredentialsDialog::urlCatched);
}

void WebFlowCredentialsDialog::closeEvent(QCloseEvent* e) {
Q_UNUSED(e);

// Force calling WebView::~WebView() earlier so that _profile and _page are
// deleted in the correct order.
delete _webView;
}

void WebFlowCredentialsDialog::setUrl(const QUrl &url) {
_webView->setUrl(url);
}
Expand Down
3 changes: 3 additions & 0 deletions src/gui/creds/webflowcredentialsdialog.h
Expand Up @@ -21,6 +21,9 @@ class WebFlowCredentialsDialog : public QDialog
void setInfo(const QString &msg);
void setError(const QString &error);

protected:
void closeEvent(QCloseEvent * e) override;

signals:
void urlCatched(const QString user, const QString pass, const QString host);

Expand Down
13 changes: 13 additions & 0 deletions src/gui/wizard/webview.cpp
Expand Up @@ -105,6 +105,19 @@ void WebView::setUrl(const QUrl &url) {
_page->setUrl(url);
}

WebView::~WebView() {
/*
* The Qt implmentation deletes children in the order they are added to the
* object tree, so in this case _page is deleted after _profile, which
* violates the assumption that _profile should exist longer than
* _page [1]. Here I delete _page manually so that _profile can be safely
* deleted later.
*
* [1] https://doc.qt.io/qt-5/qwebenginepage.html#QWebEnginePage-1
*/
delete _page;
}

WebViewPageUrlRequestInterceptor::WebViewPageUrlRequestInterceptor(QObject *parent)
: QWebEngineUrlRequestInterceptor(parent) {

Expand Down
1 change: 1 addition & 0 deletions src/gui/wizard/webview.h
Expand Up @@ -21,6 +21,7 @@ class WebView : public QWidget
Q_OBJECT
public:
WebView(QWidget *parent = nullptr);
virtual ~WebView();
void setUrl(const QUrl &url);

signals:
Expand Down