From c5133f6088a8ea18cbce14376347059d80782b00 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 22 Nov 2016 11:58:18 +0100 Subject: [PATCH] db/update/Container: catch C++ exceptions --- src/db/update/Container.cxx | 70 ++++++++++++++---------- src/decoder/plugins/GmeDecoderPlugin.cxx | 4 +- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/db/update/Container.cxx b/src/db/update/Container.cxx index 28bb7e5f1..c56ed1eb8 100644 --- a/src/db/update/Container.cxx +++ b/src/db/update/Container.cxx @@ -96,38 +96,50 @@ UpdateWalk::UpdateContainerFile(Directory &directory, return false; } - const auto v = plugin.container_scan(pathname); - if (v.empty()) { - editor.LockDeleteDirectory(contdir); - return false; - } - - TagBuilder tag_builder; - for (const auto &vtrack : v) { - Song *song = Song::NewFile(vtrack.c_str(), *contdir); - - // shouldn't be necessary but it's there.. - song->mtime = info.mtime; - - const auto vtrack_fs = AllocatedPath::FromUTF8(vtrack.c_str()); - // TODO: check vtrack_fs.IsNull() - - const auto child_path_fs = AllocatedPath::Build(pathname, - vtrack_fs); - plugin.ScanFile(child_path_fs, - add_tag_handler, &tag_builder); - - tag_builder.Commit(song->tag); - - { - const ScopeDatabaseLock protect; - contdir->AddSong(song); + try { + const auto v = plugin.container_scan(pathname); + if (v.empty()) { + editor.LockDeleteDirectory(contdir); + return false; } - modified = true; + TagBuilder tag_builder; + for (const auto &vtrack : v) { + Song *song = Song::NewFile(vtrack.c_str(), *contdir); - FormatDefault(update_domain, "added %s/%s", - directory.GetPath(), vtrack.c_str()); + // shouldn't be necessary but it's there.. + song->mtime = info.mtime; + + try { + const auto vtrack_fs = + AllocatedPath::FromUTF8Throw(vtrack.c_str()); + + const auto child_path_fs = AllocatedPath::Build(pathname, + vtrack_fs); + plugin.ScanFile(child_path_fs, + add_tag_handler, &tag_builder); + } catch (const std::runtime_error &e) { + song->Free(); + LogError(e); + continue; + } + + tag_builder.Commit(song->tag); + + { + const ScopeDatabaseLock protect; + contdir->AddSong(song); + } + + modified = true; + + FormatDefault(update_domain, "added %s/%s", + directory.GetPath(), vtrack.c_str()); + } + } catch (const std::runtime_error &e) { + editor.LockDeleteDirectory(contdir); + LogError(e); + return false; } return true; diff --git a/src/decoder/plugins/GmeDecoderPlugin.cxx b/src/decoder/plugins/GmeDecoderPlugin.cxx index 40797efad..acb6745f2 100644 --- a/src/decoder/plugins/GmeDecoderPlugin.cxx +++ b/src/decoder/plugins/GmeDecoderPlugin.cxx @@ -266,10 +266,10 @@ ScanMusicEmu(Music_Emu *emu, unsigned song_num, assert(ti != nullptr); + AtScopeExit(ti) { gme_free_info(ti); }; + ScanGmeInfo(*ti, song_num, gme_track_count(emu), handler, handler_ctx); - - gme_free_info(ti); return true; }