diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2012-05-09 17:08:39 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-05-09 18:12:01 +0000 |
commit | 5d53f48acbbba0ac80e8a26545a3ecaf8d139356 (patch) | |
tree | c0662270cecfb7198a549986a9754814ec462276 /src/bitcoinrpc.cpp | |
parent | 5146599b01114c568f2a8c02e1ddf8846b95d675 (diff) |
Bugfix: getmemorypool: NULL pindexPrev across CreateNewBlock, in case it fails
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r-- | src/bitcoinrpc.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 05913cd0ff..d8d65e7f42 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1760,16 +1760,26 @@ Value getmemorypool(const Array& params, bool fHelp) if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { + // Clear pindexPrev so future calls make a new block, despite any failures from here on + pindexPrev = NULL; + + // Store the pindexBest used before CreateNewBlock, to avoid races nTransactionsUpdatedLast = nTransactionsUpdated; - pindexPrev = pindexBest; + CBlockIndex* pindexPrevNew = pindexBest; nStart = GetTime(); // Create new block if(pblock) + { delete pblock; + pblock = NULL; + } pblock = CreateNewBlock(reservekey); if (!pblock) throw JSONRPCError(-7, "Out of memory"); + + // Need to update only after we know CreateNewBlock succeeded + pindexPrev = pindexPrevNew; } // Update nTime |