mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
refactor: Declare g_zmq_notification_interface as unique_ptr
Ensures better memory safety for this global. This came up during discussion of the following commit, but is not strictly required for its implementation.
This commit is contained in:
parent
883766fa45
commit
8ed4ff8e05
3 changed files with 8 additions and 9 deletions
|
@ -328,9 +328,8 @@ void Shutdown(NodeContext& node)
|
|||
|
||||
#if ENABLE_ZMQ
|
||||
if (g_zmq_notification_interface) {
|
||||
UnregisterValidationInterface(g_zmq_notification_interface);
|
||||
delete g_zmq_notification_interface;
|
||||
g_zmq_notification_interface = nullptr;
|
||||
UnregisterValidationInterface(g_zmq_notification_interface.get());
|
||||
g_zmq_notification_interface.reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1428,7 +1427,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||
g_zmq_notification_interface = CZMQNotificationInterface::Create();
|
||||
|
||||
if (g_zmq_notification_interface) {
|
||||
RegisterValidationInterface(g_zmq_notification_interface);
|
||||
RegisterValidationInterface(g_zmq_notification_interface.get());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ std::list<const CZMQAbstractNotifier*> CZMQNotificationInterface::GetActiveNotif
|
|||
return result;
|
||||
}
|
||||
|
||||
CZMQNotificationInterface* CZMQNotificationInterface::Create()
|
||||
std::unique_ptr<CZMQNotificationInterface> CZMQNotificationInterface::Create()
|
||||
{
|
||||
std::map<std::string, CZMQNotifierFactory> factories;
|
||||
factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
|
||||
|
@ -68,7 +68,7 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create()
|
|||
notificationInterface->notifiers = std::move(notifiers);
|
||||
|
||||
if (notificationInterface->Initialize()) {
|
||||
return notificationInterface.release();
|
||||
return notificationInterface;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,4 +198,4 @@ void CZMQNotificationInterface::BlockDisconnected(const std::shared_ptr<const CB
|
|||
});
|
||||
}
|
||||
|
||||
CZMQNotificationInterface* g_zmq_notification_interface = nullptr;
|
||||
std::unique_ptr<CZMQNotificationInterface> g_zmq_notification_interface;
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
std::list<const CZMQAbstractNotifier*> GetActiveNotifiers() const;
|
||||
|
||||
static CZMQNotificationInterface* Create();
|
||||
static std::unique_ptr<CZMQNotificationInterface> Create();
|
||||
|
||||
protected:
|
||||
bool Initialize();
|
||||
|
@ -43,6 +43,6 @@ private:
|
|||
std::list<std::unique_ptr<CZMQAbstractNotifier>> notifiers;
|
||||
};
|
||||
|
||||
extern CZMQNotificationInterface* g_zmq_notification_interface;
|
||||
extern std::unique_ptr<CZMQNotificationInterface> g_zmq_notification_interface;
|
||||
|
||||
#endif // BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
|
||||
|
|
Loading…
Add table
Reference in a new issue