From 995d8da491692ed1878777552a7adac27e9b1114 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 7 Oct 2013 10:10:10 -0500 Subject: [PATCH] Handle another removal case missed in prev commit. Also, the loops which only remove a single element and break or return don't need the extra logic for iteration since they don't continue iteration after removal. --- blockmanager.go | 4 +--- mempool.go | 8 ++++---- server.go | 4 +--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/blockmanager.go b/blockmanager.go index 8066de395..01833e731 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -189,9 +189,7 @@ func (b *blockManager) handleNewPeerMsg(peers *list.List, p *peer) { // is invoked from the syncHandler goroutine. func (b *blockManager) handleDonePeerMsg(peers *list.List, p *peer) { // Remove the peer from the list of candidate peers. - var enext *list.Element - for e := peers.Front(); e != nil; e = enext { - enext = e.Next() + for e := peers.Front(); e != nil; e = e.Next() { if e.Value == p { peers.Remove(e) break diff --git a/mempool.go b/mempool.go index 2909cc94b..d09a695d0 100644 --- a/mempool.go +++ b/mempool.go @@ -292,9 +292,7 @@ func (mp *txMemPool) removeOrphan(txHash *btcwire.ShaHash) { for _, txIn := range tx.TxIn { originTxHash := txIn.PreviousOutpoint.Hash if orphans, exists := mp.orphansByPrev[originTxHash]; exists { - var enext *list.Element - for e := orphans.Front(); e != nil; e = enext { - enext = e.Next() + for e := orphans.Front(); e != nil; e = e.Next() { if e.Value.(*btcwire.MsgTx) == tx { orphans.Remove(e) break @@ -701,7 +699,9 @@ func (mp *txMemPool) processOrphans(hash *btcwire.ShaHash) error { continue } - for e := orphans.Front(); e != nil; e = e.Next() { + var enext *list.Element + for e := orphans.Front(); e != nil; e = enext { + enext = e.Next() tx := e.Value.(*btcwire.MsgTx) // Remove the orphan from the orphan pool. diff --git a/server.go b/server.go index 6576b2039..90d6d3950 100644 --- a/server.go +++ b/server.go @@ -116,9 +116,7 @@ func (s *server) handleAddPeerMsg(peers *list.List, banned map[string]time.Time, // handleDonePeerMsg deals with peers that have signalled they are done. It is // invoked from the peerHandler goroutine. func (s *server) handleDonePeerMsg(peers *list.List, p *peer) bool { - var enext *list.Element - for e := peers.Front(); e != nil; e = enext { - enext = e.Next() + for e := peers.Front(); e != nil; e = e.Next() { if e.Value == p { // Issue an asynchronous reconnect if the peer was a // persistent outbound connection.