Fix access after delete in GTK2 dialog helpers

Each QGtk2*DialogHelper class owns a QGtk2Dialog. It is possible that
QGtk2Dialog's parent window is destroyed before QGtk2*DialogHelper.
Then the QGtk2Dialog is destroyed, because of the QWindow parent/child
relationship. Before destroying QGtk2*DialogHelper,
QQuickPlatformFileDialog calls QGtk2*DialogHelper::hide, which will
then operate on the already destroyed QGtk2Dialog.
  Break the parent/child relationship when QGtk2Dialog's parent is
destroyed.

Change-Id: Ie2bda234f759e7bf4d0642accd82fdc38e0379c2
Task-number: QTBUG-49203
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
This commit is contained in:
Joerg Bornemann 2016-01-04 17:28:51 +01:00
parent a1702da020
commit 6d6707c8c3

View File

@ -71,6 +71,9 @@ Q_SIGNALS:
protected:
static void onResponse(QGtk2Dialog *dialog, int response);
private slots:
void onParentWindowDestroyed();
private:
GtkWidget *gtkWidget;
};
@ -108,6 +111,8 @@ void QGtk2Dialog::exec()
bool QGtk2Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
{
connect(parent, &QWindow::destroyed, this, &QGtk2Dialog::onParentWindowDestroyed,
Qt::UniqueConnection);
setParent(parent);
setFlags(flags);
setModality(modality);
@ -144,6 +149,12 @@ void QGtk2Dialog::onResponse(QGtk2Dialog *dialog, int response)
emit dialog->reject();
}
void QGtk2Dialog::onParentWindowDestroyed()
{
// The QGtk2*DialogHelper classes own this object. Make sure the parent doesn't delete it.
setParent(0);
}
QGtk2ColorDialogHelper::QGtk2ColorDialogHelper()
{
d.reset(new QGtk2Dialog(gtk_color_selection_dialog_new("")));