aboutsummaryrefslogtreecommitdiff
path: root/src/rest.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-11-18 16:30:51 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2014-11-18 16:32:48 +0100
commite2f30d547f733ee33e7814ab500c08d12958e66a (patch)
treedda0ff263be6a9d329ee83293414b4a784866da4 /src/rest.cpp
parent7715c847472f565ca79429db0d8505f126617878 (diff)
Properly lock cs_main in rest_block
Diffstat (limited to 'src/rest.cpp')
-rw-r--r--src/rest.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/rest.cpp b/src/rest.cpp
index 89075887a0..9a8793a517 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -11,6 +11,7 @@
#include "core/transaction.h"
#include "version.h"
#include "main.h"
+#include "sync.h"
using namespace std;
using namespace json_spirit;
@@ -80,13 +81,17 @@ static bool rest_block(AcceptedConnection *conn,
if (!ParseHashStr(hashStr, hash))
throw RESTERR(HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
- if (mapBlockIndex.count(hash) == 0)
- throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
-
CBlock block;
- CBlockIndex* pblockindex = mapBlockIndex[hash];
- if (!ReadBlockFromDisk(block, pblockindex))
- throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
+ CBlockIndex* pblockindex = NULL;
+ {
+ LOCK(cs_main);
+ if (mapBlockIndex.count(hash) == 0)
+ throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
+
+ pblockindex = mapBlockIndex[hash];
+ if (!ReadBlockFromDisk(block, pblockindex))
+ throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
+ }
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
ssBlock << block;