From: Jeff Garzik Date: Fri, 13 Apr 2012 22:24:55 +0000 (-0400) Subject: Locking fix for AlreadyHave() X-Git-Tag: v0.4.0-unstable~129^2~67^2 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=8deb9822e41602001b399944d8a182f48bc9d088 Locking fix for AlreadyHave() Access to mapTransactions[] must be guarded by cs_mapTransactions lock. Also, reformat long lines to make the switch statement more readable. --- diff --git a/src/main.cpp b/src/main.cpp index bdafae8..c9368cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2137,8 +2137,17 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv) { switch (inv.type) { - case MSG_TX: return mapTransactions.count(inv.hash) || mapOrphanTransactions.count(inv.hash) || txdb.ContainsTx(inv.hash); - case MSG_BLOCK: return mapBlockIndex.count(inv.hash) || mapOrphanBlocks.count(inv.hash); + case MSG_TX: + { + LOCK(cs_mapTransactions); + return mapTransactions.count(inv.hash) || + mapOrphanTransactions.count(inv.hash) || + txdb.ContainsTx(inv.hash); + } + + case MSG_BLOCK: + return mapBlockIndex.count(inv.hash) || + mapOrphanBlocks.count(inv.hash); } // Don't know what it is, just say we already got one return true;