use weak_ptr instead of bare pointer to prevent use after free

pull/1681/head
Jeff Becker 3 years ago
parent aa48a1de1b
commit abd6e4c558
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -195,8 +195,16 @@ namespace llarp
OutboundContext::HandlePathBuilt(path::Path_ptr p)
{
path::Builder::HandlePathBuilt(p);
p->SetDataHandler(util::memFn(&OutboundContext::HandleHiddenServiceFrame, this));
p->SetDropHandler(util::memFn(&OutboundContext::HandleDataDrop, this));
p->SetDataHandler([self = weak_from_this()](auto path, auto frame) {
if (auto ptr = self.lock())
return ptr->HandleHiddenServiceFrame(path, frame);
return false;
});
p->SetDropHandler([self = weak_from_this()](auto path, auto id, auto seqno) {
if (auto ptr = self.lock())
return ptr->HandleDataDrop(path, id, seqno);
return false;
});
if (markedBad)
{
// ignore new path if we are marked dead

Loading…
Cancel
Save