diff --git a/src/zmq/zmqabstractnotifier.h b/src/zmq/zmqabstractnotifier.h --- a/src/zmq/zmqabstractnotifier.h +++ b/src/zmq/zmqabstractnotifier.h @@ -7,10 +7,12 @@ #include +#include + class CBlockIndex; class CZMQAbstractNotifier; -typedef CZMQAbstractNotifier *(*CZMQNotifierFactory)(); +using CZMQNotifierFactory = std::unique_ptr (*)(); class CZMQAbstractNotifier { public: @@ -21,8 +23,9 @@ outbound_message_high_water_mark(DEFAULT_ZMQ_SNDHWM) {} virtual ~CZMQAbstractNotifier(); - template static CZMQAbstractNotifier *Create() { - return new T(); + template + static std::unique_ptr Create() { + return std::make_unique(); } std::string GetType() const { return type; } diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -43,15 +43,15 @@ for (const auto &entry : factories) { std::string arg("-zmq" + entry.first); if (gArgs.IsArgSet(arg)) { - CZMQNotifierFactory factory = entry.second; - std::string address = gArgs.GetArg(arg, ""); - CZMQAbstractNotifier *notifier = factory(); + const auto &factory = entry.second; + const std::string address = gArgs.GetArg(arg, ""); + std::unique_ptr notifier = factory(); notifier->SetType(entry.first); notifier->SetAddress(address); notifier->SetOutboundMessageHighWaterMark( static_cast(gArgs.GetArg( arg + "hwm", CZMQAbstractNotifier::DEFAULT_ZMQ_SNDHWM))); - notifiers.emplace_back(notifier); + notifiers.push_back(std::move(notifier)); } }