From b0b4e0fa7f12e2135b3a2d0310b9ee4a37782f57 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Mon, 17 Apr 2023 10:42:49 +0200 Subject: [PATCH] zmq: Make `g_zmq_notification_interface` a smart pointer courtesy of 8ed4ff8e from bitcoin#27125 --- src/init.cpp | 7 +++---- src/zmq/zmqnotificationinterface.cpp | 6 +++--- src/zmq/zmqnotificationinterface.h | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 88e981898a..eeb9514f08 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -360,9 +360,8 @@ void PrepareShutdown(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 @@ -1737,7 +1736,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 diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index a0d004820c..7539ca3114 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -29,7 +29,7 @@ std::list CZMQNotificationInterface::GetActiveNotif return result; } -CZMQNotificationInterface* CZMQNotificationInterface::Create() +std::unique_ptr CZMQNotificationInterface::Create() { std::map factories; factories["pubhashblock"] = CZMQAbstractNotifier::Create; @@ -71,7 +71,7 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create() notificationInterface->notifiers = std::move(notifiers); if (notificationInterface->Initialize()) { - return notificationInterface.release(); + return notificationInterface; } } @@ -219,4 +219,4 @@ void CZMQNotificationInterface::NotifyRecoveredSig(const std::shared_ptr g_zmq_notification_interface; diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index 230dd6c8ff..8cfc12de37 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -19,7 +19,7 @@ public: std::list GetActiveNotifiers() const; - static CZMQNotificationInterface* Create(); + static std::unique_ptr Create(); protected: bool Initialize(); @@ -44,6 +44,6 @@ private: std::list> notifiers; }; -extern CZMQNotificationInterface* g_zmq_notification_interface; +extern std::unique_ptr g_zmq_notification_interface; #endif // BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H