diff options
author | Max Kellermann <max@musicpd.org> | 2019-02-15 18:03:43 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-02-15 18:04:23 +0100 |
commit | 99c23cf13993cde427f66a9dd6e433bdc7c63963 (patch) | |
tree | f300813aaa8c047e2de6f7fc9049cda0ffe0886f /src | |
parent | 9aa75e738cb98d3f9794300d2eea20027c603c48 (diff) |
Instance: eliminate ShutdownDatabase(), move code to destructor
Destruct automatically, even if leaving the scope due to exception
being thrown.
Diffstat (limited to 'src')
-rw-r--r-- | src/Instance.cxx | 14 | ||||
-rw-r--r-- | src/Instance.hxx | 1 | ||||
-rw-r--r-- | src/Main.cxx | 14 |
3 files changed, 13 insertions, 16 deletions
diff --git a/src/Instance.cxx b/src/Instance.cxx index f1beeeff6..a66244f5b 100644 --- a/src/Instance.cxx +++ b/src/Instance.cxx @@ -30,6 +30,8 @@ #ifdef ENABLE_DATABASE #include "db/DatabaseError.hxx" +#include "db/Interface.hxx" +#include "storage/StorageInterface.hxx" #ifdef ENABLE_SQLITE #include "sticker/StickerDatabase.hxx" @@ -48,7 +50,17 @@ Instance::Instance() { } -Instance::~Instance() noexcept = default; +Instance::~Instance() noexcept +{ +#ifdef ENABLE_DATABASE + if (database != nullptr) { + database->Close(); + delete database; + } + + delete storage; +#endif +} Partition * Instance::FindPartition(const char *name) noexcept diff --git a/src/Instance.hxx b/src/Instance.hxx index 48e5a2f79..996ca7475 100644 --- a/src/Instance.hxx +++ b/src/Instance.hxx @@ -168,7 +168,6 @@ struct Instance final void BeginShutdownUpdate() noexcept; void FinishShutdownUpdate() noexcept; - void ShutdownDatabase() noexcept; #ifdef ENABLE_CURL void LookupRemoteTag(const char *uri) noexcept; diff --git a/src/Main.cxx b/src/Main.cxx index e5046a7ad..c2d96847c 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -360,19 +360,6 @@ Instance::FinishShutdownUpdate() noexcept } inline void -Instance::ShutdownDatabase() noexcept -{ -#ifdef ENABLE_DATABASE - if (instance->database != nullptr) { - instance->database->Close(); - delete instance->database; - } - - delete instance->storage; -#endif -} - -inline void Instance::BeginShutdownPartitions() noexcept { for (auto &partition : partitions) { @@ -648,7 +635,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) #endif instance->FinishShutdownUpdate(); - instance->ShutdownDatabase(); #ifdef ENABLE_SQLITE sticker_global_finish(); |