aboutsummaryrefslogtreecommitdiff
path: root/src/zmq
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-04-17 10:42:49 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-05-10 12:56:46 +0200
commit8ed4ff8e05d61a8e954d72cebdc2e1d1ab24fb84 (patch)
treec38716718172c794faed922da13879014af34847 /src/zmq
parent883766fa4517d310839c8968994d1fb4effdc7c2 (diff)
downloadbitcoin-8ed4ff8e05d61a8e954d72cebdc2e1d1ab24fb84.tar.xz
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.
Diffstat (limited to 'src/zmq')
-rw-r--r--src/zmq/zmqnotificationinterface.cpp6
-rw-r--r--src/zmq/zmqnotificationinterface.h4
2 files changed, 5 insertions, 5 deletions
diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp
index 9920d80a69..2ed0c93fc3 100644
--- a/src/zmq/zmqnotificationinterface.cpp
+++ b/src/zmq/zmqnotificationinterface.cpp
@@ -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;
diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h
index a43f9bfef3..4aef87c5a4 100644
--- a/src/zmq/zmqnotificationinterface.h
+++ b/src/zmq/zmqnotificationinterface.h
@@ -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