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.
This commit is contained in:
Olaoluwa Osuntokun 2022-01-06 15:36:15 -08:00
parent ed511bb37f
commit ae16f2b631
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

View File

@ -2044,6 +2044,7 @@ func (p *Brontide) pingHandler() {
"subscription: %v", err) "subscription: %v", err)
return return
} }
defer blockEpochs.Cancel()
var ( var (
pingPayload [wire.MaxBlockHeaderPayload]byte pingPayload [wire.MaxBlockHeaderPayload]byte