From 04eb07c26f8af63e95d5f1ccac0b0c05c5fe0f42 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Tue, 8 Jul 2014 08:34:49 -0700 Subject: [PATCH] fixed a bug --- p2p/peer_set.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/p2p/peer_set.go b/p2p/peer_set.go index 2151a707d..ade9abcac 100644 --- a/p2p/peer_set.go +++ b/p2p/peer_set.go @@ -50,14 +50,15 @@ func (ps *PeerSet) Remove(peer *Peer) { return } index := item.index + // Copy the list but without the last element. + // (we must copy because we're mutating the list) + newList := make([]*Peer, len(ps.list)-1) + copy(newList, ps.list) // If it's the last peer, that's an easy special case. if index == len(ps.list)-1 { - ps.list = ps.list[:len(ps.list)-1] + ps.list = newList return } - // Copy the list but without the last element. - newList := make([]*Peer, len(ps.list)-1) - copy(newList, ps.list) // Move the last item from ps.list to "index" in list. lastPeer := ps.list[len(ps.list)-1] lastPeerAddr := lastPeer.RemoteAddress().String()