From ae16f2b631de88e2394a48a034ea932a9e80f66e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 6 Jan 2022 15:36:15 -0800 Subject: [PATCH] peer: always defer clean up of the block epoch client used for ping headers In this commit, we fix an inadvertent memory leak by ensuring we always use `defer` to clean up the allocated objects/memory we use to be notified of new blocks to update what we send within the set of ping headers. A further optimization here would be using a single global block epoch housed within the server, that all peer `pingHandler` goroutines use directly. Fixes #6143. --- peer/brontide.go | 1 + 1 file changed, 1 insertion(+) diff --git a/peer/brontide.go b/peer/brontide.go index 257dcdac0..e58b703dc 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -2044,6 +2044,7 @@ func (p *Brontide) pingHandler() { "subscription: %v", err) return } + defer blockEpochs.Cancel() var ( pingPayload [wire.MaxBlockHeaderPayload]byte