WgPeerExtraData now uses OnDestroy so lifetime can be controlled

This commit is contained in:
Ludvig Strigeus 2018-11-23 22:44:08 +01:00
parent d04afa1cdb
commit 23b4e819ad
3 changed files with 9 additions and 2 deletions

View file

@ -171,6 +171,11 @@ class PluginPeer : public WgPeerExtraData {
public:
PluginPeer(TunsafePluginImpl *plugin, WgPeer *peer) : plugin(plugin), peer(peer), token_client_handler(this) {}
~PluginPeer();
virtual void OnPeerDestroy() override {
delete this;
}
WgPeer *peer;
TunsafePluginImpl *plugin;
TokenClientHandler token_client_handler;

View file

@ -392,7 +392,8 @@ WgPeer::~WgPeer() {
assert(curr_keypair_ == NULL && next_keypair_ == NULL && prev_keypair_ == NULL);
assert(local_key_id_during_hs_ == 0);
assert(first_queued_packet_ == NULL);
delete peer_extra_data_;
if (peer_extra_data_)
peer_extra_data_->OnPeerDestroy();
}
void WgPeer::DelayedDelete(void *x) {

View file

@ -468,7 +468,8 @@ private:
// Allows associating extradata with peers that can be used by plugins etc.
class WgPeerExtraData {
public:
virtual ~WgPeerExtraData() {}
// This is called when the peer is destroyed.
virtual void OnPeerDestroy() = 0;
};
// State for peer