From abc98cfa796f4c783cc0d1088000f9b98b44de5f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 21 Jul 2020 14:57:09 +0200 Subject: [PATCH] [locale] Simplify allocation, guard against crashes if the dialog is deleted. --- src/modules/locale/LocalePage.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index d09d38540..98383b429 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -285,31 +286,31 @@ LocalePage::locationChanged( const CalamaresUtils::Locale::TZZone* location ) void LocalePage::changeLocale() { - LCLocaleDialog* dlg - = new LCLocaleDialog( m_config->localeConfiguration().language(), m_config->supportedLocales(), this ); + QPointer< LCLocaleDialog > dlg( + new LCLocaleDialog( m_config->localeConfiguration().language(), m_config->supportedLocales(), this ) ); dlg->exec(); - if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() ) + if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() ) { m_config->setLanguageExplicitly( dlg->selectedLCLocale() ); updateGlobalLocale(); updateLocaleLabels(); } - dlg->deleteLater(); + delete dlg; } void LocalePage::changeFormats() { - LCLocaleDialog* dlg - = new LCLocaleDialog( m_config->localeConfiguration().lc_numeric, m_config->supportedLocales(), this ); + QPointer< LCLocaleDialog > dlg( + new LCLocaleDialog( m_config->localeConfiguration().lc_numeric, m_config->supportedLocales(), this ) ); dlg->exec(); - if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() ) + if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() ) { m_config->setLCLocaleExplicitly( dlg->selectedLCLocale() ); updateLocaleLabels(); } - dlg->deleteLater(); + delete dlg; }