From 7070d4c74de929c5aec0a37c563b1599515c7a89 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 2 Oct 2015 14:09:29 -0400 Subject: [PATCH] Added critical section lock in isSpent --- src/libbitcoind.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index 8a5328ca..26eb7859 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -1231,17 +1231,20 @@ NAN_METHOD(IsSpent) { const uint256 txid = uint256S(argStr); int outputIndex = info[1]->IntegerValue(); - CCoinsView dummy; - CCoinsViewCache view(&dummy); + { + LOCK(mempool.cs); + CCoinsView dummy; + CCoinsViewCache view(&dummy); - CCoinsViewMemPool viewMemPool(pcoinsTip, mempool); - view.SetBackend(viewMemPool); + CCoinsViewMemPool viewMemPool(pcoinsTip, mempool); + view.SetBackend(viewMemPool); - if (view.HaveCoins(txid)) { - const CCoins* coins = view.AccessCoins(txid); - if (coins && coins->IsAvailable(outputIndex)) { - info.GetReturnValue().Set(New(false)); - return; + if (view.HaveCoins(txid)) { + const CCoins* coins = view.AccessCoins(txid); + if (coins && coins->IsAvailable(outputIndex)) { + info.GetReturnValue().Set(New(false)); + return; + } } } info.GetReturnValue().Set(New(true));