Skip to content

Commit

Permalink
use weak_ptr instead of bare pointer to prevent use after free
Browse files Browse the repository at this point in the history
  • Loading branch information
majestrate committed Jun 25, 2021
1 parent aa48a1d commit abd6e4c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions llarp/service/outbound_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit abd6e4c

Please sign in to comment.