Instance: use std::unique_ptr<> to manage the NeighborGlue pointer

This commit is contained in:
Max Kellermann 2019-04-25 13:09:31 +02:00
parent 692c8025a2
commit f764925edc
4 changed files with 9 additions and 11 deletions

View File

@ -34,6 +34,10 @@
#include "db/update/Service.hxx" #include "db/update/Service.hxx"
#include "storage/StorageInterface.hxx" #include "storage/StorageInterface.hxx"
#ifdef ENABLE_NEIGHBOR_PLUGINS
#include "neighbor/Glue.hxx"
#endif
#ifdef ENABLE_SQLITE #ifdef ENABLE_SQLITE
#include "sticker/Database.hxx" #include "sticker/Database.hxx"
#include "sticker/SongSticker.hxx" #include "sticker/SongSticker.hxx"

View File

@ -101,7 +101,7 @@ struct Instance final
MaskMonitor idle_monitor; MaskMonitor idle_monitor;
#ifdef ENABLE_NEIGHBOR_PLUGINS #ifdef ENABLE_NEIGHBOR_PLUGINS
NeighborGlue *neighbors; std::unique_ptr<NeighborGlue> neighbors;
#endif #endif
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE

View File

@ -448,15 +448,13 @@ MainOrThrow(int argc, char *argv[])
}; };
#ifdef ENABLE_NEIGHBOR_PLUGINS #ifdef ENABLE_NEIGHBOR_PLUGINS
instance->neighbors = new NeighborGlue(); instance->neighbors = std::make_unique<NeighborGlue>();
instance->neighbors->Init(raw_config, instance->neighbors->Init(raw_config,
instance->io_thread.GetEventLoop(), instance->io_thread.GetEventLoop(),
*instance); *instance);
if (instance->neighbors->IsEmpty()) { if (instance->neighbors->IsEmpty())
delete instance->neighbors; instance->neighbors.reset();
instance->neighbors = nullptr;
}
#endif #endif
const unsigned max_clients = const unsigned max_clients =
@ -625,10 +623,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
delete instance->client_list; delete instance->client_list;
#ifdef ENABLE_NEIGHBOR_PLUGINS
delete instance->neighbors;
#endif
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -37,7 +37,7 @@ CommandResult
handle_listneighbors(Client &client, gcc_unused Request args, Response &r) handle_listneighbors(Client &client, gcc_unused Request args, Response &r)
{ {
const NeighborGlue *const neighbors = const NeighborGlue *const neighbors =
client.GetInstance().neighbors; client.GetInstance().neighbors.get();
if (neighbors == nullptr) { if (neighbors == nullptr) {
r.Error(ACK_ERROR_UNKNOWN, "No neighbor plugin configured"); r.Error(ACK_ERROR_UNKNOWN, "No neighbor plugin configured");
return CommandResult::ERROR; return CommandResult::ERROR;