AlreadyHave(): only hold lock during mapTransactions access
authorJeff Garzik <jeff@garzik.org>
Tue, 17 Apr 2012 16:30:00 +0000 (12:30 -0400)
committerLuke Dashjr <luke-jr+git@utopios.org>
Tue, 17 Apr 2012 18:40:58 +0000 (14:40 -0400)
src/main.cpp

index 57c18ae..f13b884 100644 (file)
@@ -1954,11 +1954,15 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv)
     switch (inv.type)
     {
     case MSG_TX:
+        {
+        bool txInMap = false;
         CRITICAL_BLOCK(cs_mapTransactions)
         {
-            return mapTransactions.count(inv.hash) ||
-                   mapOrphanTransactions.count(inv.hash) ||
-                   txdb.ContainsTx(inv.hash);
+            txInMap = (mapTransactions.count(inv.hash) != 0);
+        }
+        return txInMap ||
+               mapOrphanTransactions.count(inv.hash) ||
+               txdb.ContainsTx(inv.hash);
         }
 
     case MSG_BLOCK: return mapBlockIndex.count(inv.hash) || mapOrphanBlocks.count(inv.hash);