Page MenuHomePhabricator

refactor: Declare g_zmq_notification_interface as unique_ptr
ClosedPublic

Authored by PiRK on May 20 2024, 09:43.

Details

Summary

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 is a partial backport of core#27125
https://github.com/bitcoin/bitcoin/pull/27125/commits/8ed4ff8e05d61a8e954d72cebdc2e1d1ab24fb84

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.May 20 2024, 09:43
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/zmq/zmqnotificationinterface.cpp
59 ↗(On Diff #47828)

While you're at it, it can use make_unique:

auto notificationInterface = std::make_unique<CZMQNotificationInterface>();
This revision is now accepted and ready to land.May 20 2024, 11:12

mq

src/zmq/zmqnotificationinterface.cpp
59 ↗(On Diff #47828)

It does not work because the constructor is private.

/usr/include/c++/11/bits/unique_ptr.h:962:30: error: ‘CZMQNotificationInterface::CZMQNotificationInterface()’ is private within this context

It is a bit weird, the Create member function can access the private constructor from the same class, but not when the ctor call is wrapped in a std::make_unique call.