Cleanup: use ScopeGuard.
authorCarl Hetherington <cth@carlh.net>
Mon, 5 Dec 2022 19:44:42 +0000 (20:44 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 5 Dec 2022 19:44:42 +0000 (20:44 +0100)
src/wx/content_panel.cc

index bf02e39305146fe3d650f2fd9bd2a556add4c789..1a5dbdc51952b50e013bf40405954b0b214895e2 100644 (file)
@@ -43,6 +43,7 @@
 #include "lib/image_content.h"
 #include "lib/log.h"
 #include "lib/playlist.h"
+#include "lib/scope_guard.h"
 #include "lib/string_text_file.h"
 #include "lib/string_text_file_content.h"
 #include "lib/text_content.h"
@@ -619,14 +620,13 @@ void
 ContentPanel::add_folder_clicked ()
 {
        auto d = new wxDirDialog (_splitter, _("Choose a folder"), wxT(""), wxDD_DIR_MUST_EXIST);
+       ScopeGuard sg = [d]() { d->Destroy(); };
        int r = d->ShowModal ();
-       boost::filesystem::path const path (wx_to_std (d->GetPath ()));
-       d->Destroy ();
-
        if (r != wxID_OK) {
                return;
        }
 
+       boost::filesystem::path const path(wx_to_std(d->GetPath()));
        add_folder(path);
 }