bitcoin/bitcoin — pull request #1245 by luke-jr (2012-05-09 17:12:56+00:00)
Title: Bugfix: getwork/getmemorypool: NULL pindexPrev across CreateNewBlock, in case it fails

Without this, the following bugs are possible:
1. NULL pointer dereference
- CreateNewBlock returns NULL (out of memory); pblock is left NULL and JSON error thrown
- Next call sees pindexPrev/nTransactionsUpdatedLast/nStart up to date, so skips over making a new one
- This next call then tries to update the time on the "current" pblock (NULL)
2. Deleted object dereference
- CreateNewBlock throws an exception (not sure if this is possible right now); pblock is left with a pointer to a deleted CBlock
- Next call sees pindexPrev/nTransactionsUpdatedLast/nStart up to date, so skips over making a new one
- This next call then tried to update the time on the 'current' pblock (which is deleted)
- Consequences of this memory corruption are undefined!