Skip to content

Commit 2b3ea39

Browse files
committed
Polish interfaces around PeerLogicValidation
* Make PeerLogicValidation final to prevent deriving from it [1] * Prevent deletions of NetEventsInterface and CValidationInterface objects via a base class pointer [1] silences the following compiler warning (from Clang 7.0.0): /usr/include/c++/v1/memory:2285:5: error: delete called on non-final 'PeerLogicValidation' that has virtual functions but non-virtual destructor [-Werror,-Wdelete-non-virtual-dtor] delete __ptr; ^ /usr/include/c++/v1/memory:2598:7: note: in instantiation of member function 'std::__1::default_delete<PeerLogicValidation>::operator()' requested here __ptr_.second()(__tmp); ^ init.cpp:201:15: note: in instantiation of member function 'std::__1::unique_ptr<PeerLogicValidation, std::__1::default_delete<PeerLogicValidation> >::reset' requested here peerLogic.reset(); ^
1 parent 6acd870 commit 2b3ea39

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/net.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,13 @@ class NetEventsInterface
469469
virtual bool SendMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
470470
virtual void InitializeNode(CNode* pnode) = 0;
471471
virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
472+
473+
protected:
474+
/**
475+
* Protected destructor so that instances can only be deleted by derived classes.
476+
* If that restriction is no longer desired, this should be made public and virtual.
477+
*/
478+
~NetEventsInterface() = default;
472479
};
473480

474481
enum

src/net_processing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45;
3535
/** Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds */
3636
static constexpr int64_t MINIMUM_CONNECT_TIME = 30;
3737

38-
class PeerLogicValidation : public CValidationInterface, public NetEventsInterface {
38+
class PeerLogicValidation final : public CValidationInterface, public NetEventsInterface {
3939
private:
4040
CConnman* const connman;
4141

src/validationinterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ void SyncWithValidationInterfaceQueue();
5555

5656
class CValidationInterface {
5757
protected:
58+
/**
59+
* Protected destructor so that instances can only be deleted by derived classes.
60+
* If that restriction is no longer desired, this should be made public and virtual.
61+
*/
62+
~CValidationInterface() = default;
5863
/**
5964
* Notifies listeners of updated block chain tip
6065
*

0 commit comments

Comments
 (0)