Mercurial > hg > bitcoin
changeset 3007:f038cbb2a3f0 draft
Always check return values of TxnBegin() and TxnCommit()
author | Jeff Garzik <jgarzik@exmulti.com> |
---|---|
date | Mon, 14 May 2012 01:11:11 -0400 |
parents | 6ab0bf3b68e4 |
children | 1e2acc8df636 |
files | src/bitcoinrpc.cpp src/main.cpp src/wallet.cpp |
diffstat | 3 files changed, 15 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -840,7 +840,8 @@ strComment = params[4].get_str(); CWalletDB walletdb(pwalletMain->strWalletFile); - walletdb.TxnBegin(); + if (!walletdb.TxnBegin()) + throw JSONRPCError(-20, "database error"); int64 nNow = GetAdjustedTime(); @@ -862,7 +863,8 @@ credit.strComment = strComment; walletdb.WriteAccountingEntry(credit); - walletdb.TxnCommit(); + if (!walletdb.TxnCommit()) + throw JSONRPCError(-20, "database error"); return true; }
--- a/src/main.cpp +++ b/src/main.cpp @@ -1496,7 +1496,9 @@ { uint256 hash = GetHash(); - txdb.TxnBegin(); + if (!txdb.TxnBegin()) + return error("SetBestChain() : TxnBegin failed"); + if (pindexGenesisBlock == NULL && hash == hashGenesisBlock) { txdb.WriteHashBestChain(hash); @@ -1545,7 +1547,10 @@ printf("SetBestChain() : ReadFromDisk failed\n"); break; } - txdb.TxnBegin(); + if (!txdb.TxnBegin()) { + printf("SetBestChain() : TxnBegin 2 failed\n"); + break; + } // errors now are not fatal, we still did a reorganisation to a new chain in a valid way if (!block.SetBestChainInner(txdb, pindex)) break; @@ -1603,7 +1608,8 @@ pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork(); CTxDB txdb; - txdb.TxnBegin(); + if (!txdb.TxnBegin()) + return false; txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew)); if (!txdb.TxnCommit()) return false;