mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 01:40:07 +01:00
wire/server: allocate hash once per loop to prevent overwriting
This commit is contained in:
parent
71ccc95502
commit
ba4a2f77a5
@ -839,7 +839,6 @@ func (sp *serverPeer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
|
||||
// Generate cfheaders message and send it.
|
||||
headersMsg := wire.NewMsgCFHeaders()
|
||||
var header chainhash.Hash
|
||||
for i := range hashList {
|
||||
// Fetch the raw committed filter header bytes from the
|
||||
// database.
|
||||
@ -852,6 +851,7 @@ func (sp *serverPeer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
|
||||
}
|
||||
|
||||
// Deserialize the hash.
|
||||
var header chainhash.Hash
|
||||
err = header.SetBytes(headerBytes)
|
||||
if err != nil {
|
||||
peerLog.Warnf("Committed filter header deserialize "+
|
||||
|
@ -60,9 +60,9 @@ func (msg *MsgCFHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
|
||||
// Create a contiguous slice of headers to deserialize into in order to
|
||||
// reduce the number of allocations.
|
||||
var cfh chainhash.Hash
|
||||
msg.HeaderHashes = make([]*chainhash.Hash, 0, count)
|
||||
for i := uint64(0); i < count; i++ {
|
||||
var cfh chainhash.Hash
|
||||
err := readElement(r, &cfh)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user