Instance: eliminate ShutdownDatabase(), move code to destructor

Destruct automatically, even if leaving the scope due to exception
being thrown.
This commit is contained in:
Max Kellermann 2019-02-15 18:03:43 +01:00
parent 9aa75e738c
commit 99c23cf139
3 changed files with 13 additions and 16 deletions

View File

@ -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

View File

@ -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;

View File

@ -359,19 +359,6 @@ Instance::FinishShutdownUpdate() noexcept
#endif
}
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
{
@ -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();