Commit f764925e authored by Max Kellermann's avatar Max Kellermann

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

parent 692c8025
......@@ -34,6 +34,10 @@
#include "db/update/Service.hxx"
#include "storage/StorageInterface.hxx"
#ifdef ENABLE_NEIGHBOR_PLUGINS
#include "neighbor/Glue.hxx"
#endif
#ifdef ENABLE_SQLITE
#include "sticker/Database.hxx"
#include "sticker/SongSticker.hxx"
......
......@@ -101,7 +101,7 @@ struct Instance final
MaskMonitor idle_monitor;
#ifdef ENABLE_NEIGHBOR_PLUGINS
NeighborGlue *neighbors;
std::unique_ptr<NeighborGlue> neighbors;
#endif
#ifdef ENABLE_DATABASE
......
......@@ -448,15 +448,13 @@ MainOrThrow(int argc, char *argv[])
};
#ifdef ENABLE_NEIGHBOR_PLUGINS
instance->neighbors = new NeighborGlue();
instance->neighbors = std::make_unique<NeighborGlue>();
instance->neighbors->Init(raw_config,
instance->io_thread.GetEventLoop(),
*instance);
if (instance->neighbors->IsEmpty()) {
delete instance->neighbors;
instance->neighbors = nullptr;
}
if (instance->neighbors->IsEmpty())
instance->neighbors.reset();
#endif
const unsigned max_clients =
......@@ -625,10 +623,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
delete instance->client_list;
#ifdef ENABLE_NEIGHBOR_PLUGINS
delete instance->neighbors;
#endif
return EXIT_SUCCESS;
}
......
......@@ -37,7 +37,7 @@ CommandResult
handle_listneighbors(Client &client, gcc_unused Request args, Response &r)
{
const NeighborGlue *const neighbors =
client.GetInstance().neighbors;
client.GetInstance().neighbors.get();
if (neighbors == nullptr) {
r.Error(ACK_ERROR_UNKNOWN, "No neighbor plugin configured");
return CommandResult::ERROR;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment