From bc6ff038e389b399e08e032d27ad1227ecee8b55 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 5 Feb 2014 12:37:35 -0600 Subject: [PATCH] Fix a race in the amgr found by the race detector. --- addrmanager.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addrmanager.go b/addrmanager.go index 854dab209..fe54abfe8 100644 --- a/addrmanager.go +++ b/addrmanager.go @@ -140,7 +140,11 @@ func (a *AddrManager) updateAddress(netAddr, srcAddr *btcwire.NetAddress) { return } } else { - ka = &knownAddress{na: netAddr, srcAddr: srcAddr} + // Make a copy of the net address to avoid races since it is + // updated elsewhere in the addrmanager code and would otherwise + // change the actual netaddress on the peer. + netAddrCopy := *netAddr + ka = &knownAddress{na: &netAddrCopy, srcAddr: srcAddr} a.addrIndex[addr] = ka a.nNew++ // XXX time penalty?