Locking fix for AlreadyHave()
authorJeff Garzik <jeff@garzik.org>
Fri, 13 Apr 2012 22:24:55 +0000 (18:24 -0400)
committerLuke Dashjr <luke-jr+git@utopios.org>
Tue, 17 Apr 2012 17:20:29 +0000 (13:20 -0400)
Access to mapTransactions[] must be guarded by cs_mapTransactions lock.

src/main.cpp

index 059dd3d..57c18ae 100644 (file)
@@ -1953,7 +1953,14 @@ 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_TX:
+        CRITICAL_BLOCK(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