Use more ScopeGuards.
[dcpomatic.git] / src / wx / screen_dialog.cc
index 1f1fc2fad7ae746170dad7d2088c776e6a2d78fc..6d7fb4f031c530a33e7bad64b7cc16a74daa16b4 100644 (file)
@@ -272,12 +272,12 @@ ScreenDialog::get_recipient_from_file ()
 void
 ScreenDialog::download_recipient ()
 {
-       auto d = new DownloadCertificateDialog (this);
-       if (d->ShowModal() == wxID_OK) {
-               set_recipient (d->certificate());
-               checked_set (_recipient_file, d->url());
+       auto dialog = new DownloadCertificateDialog (this);
+       ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+       if (dialog->ShowModal() == wxID_OK) {
+               set_recipient(dialog->certificate());
+               checked_set(_recipient_file, dialog->url());
        }
-       d->Destroy ();
        setup_sensitivity ();
 }