From 397d8b01fca2a9da23135703a5a7c472609d82f5 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 2 May 2021 17:52:29 -0400 Subject: [PATCH] try fixing std::shared_ptr leak with paths --- llarp/path/pathbuilder.cpp | 54 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 3fdb4d9ba..f833dd9f3 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -96,7 +96,10 @@ namespace llarp { // farthest hop // TODO: encrypt junk frames because our public keys are not eligator - loop->call([self = shared_from_this()] { self->result(self); }); + loop->call([self = shared_from_this()] { + self->result(self); + self->result = nullptr; + }); } else { @@ -125,36 +128,31 @@ namespace llarp static void PathBuilderKeysGenerated(std::shared_ptr ctx) { - if (!ctx->pathset->IsStopped()) - { - ctx->router->NotifyRouterEvent(ctx->router->pubkey(), ctx->path); + if (ctx->pathset->IsStopped()) + return; - const RouterID remote = ctx->path->Upstream(); - auto sentHandler = [ctx](auto status) { - if (status == SendStatus::Success) - { - ctx->router->pathContext().AddOwnPath(ctx->pathset, ctx->path); - ctx->pathset->PathBuildStarted(std::move(ctx->path)); - } - else - { - LogError(ctx->pathset->Name(), " failed to send LRCM to ", ctx->path->Upstream()); - ctx->path->EnterState(path::ePathFailed, ctx->router->Now()); - } - ctx->path = nullptr; - ctx->pathset = nullptr; - }; - if (ctx->router->SendToOrQueue(remote, ctx->LRCM, sentHandler)) - { - // persist session with router until this path is done - if (ctx->path) - ctx->router->PersistSessionUntil(remote, ctx->path->ExpireTime()); - } - else + ctx->router->NotifyRouterEvent(ctx->router->pubkey(), ctx->path); + + ctx->router->pathContext().AddOwnPath(ctx->pathset, ctx->path); + ctx->pathset->PathBuildStarted(ctx->path); + + const RouterID remote = ctx->path->Upstream(); + auto sentHandler = [router = ctx->router, path = ctx->path](auto status) { + if (status != SendStatus::Success) { - LogError(ctx->pathset->Name(), " failed to queue LRCM to ", remote); - sentHandler(SendStatus::NoLink); + path->EnterState(path::ePathFailed, router->Now()); } + }; + if (ctx->router->SendToOrQueue(remote, ctx->LRCM, sentHandler)) + { + // persist session with router until this path is done + if (ctx->path) + ctx->router->PersistSessionUntil(remote, ctx->path->ExpireTime()); + } + else + { + LogError(ctx->pathset->Name(), " failed to queue LRCM to ", remote); + sentHandler(SendStatus::NoLink); } }