QmlDesigner: Avoid potential double-free in FormEditorAnnotationIcon

You need a QPointer here to avoid potential double-free. A normal
pointer is not reset to nullptr when the widget gets cleaned via
the widget tree, so if (widget) widget->deleteLater() does not
work with a normal pointer.

Change-Id: I18460c44414ff2ee90d8afe3a857d5902d69f911
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Tobias Hunger
2020-02-24 11:17:19 +01:00
committed by Thomas Hartmann
parent 836bf1f379
commit d22815f208

View File

@@ -407,14 +407,15 @@ void FormEditorAnnotationIcon::removeAnnotationDialog()
if (!m_customId.isNull()) {
dialogTitle = m_customId;
}
QMessageBox *deleteDialog = new QMessageBox(Core::ICore::dialogParent());
QPointer<QMessageBox> deleteDialog = new QMessageBox(Core::ICore::dialogParent());
deleteDialog->setWindowTitle(dialogTitle);
deleteDialog->setText(tr("Delete this annotation?"));
deleteDialog->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
deleteDialog->setDefaultButton(QMessageBox::Yes);
int result = deleteDialog->exec();
if (deleteDialog) deleteDialog->deleteLater();
if (deleteDialog)
deleteDialog->deleteLater();
if (result == QMessageBox::Yes) {
m_modelNode.removeCustomId();