aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-05-17 08:49:16 -0700
committerJeff Garzik <jgarzik@exmulti.com>2012-05-17 08:49:16 -0700
commitcf2f7c30a3b461c8db8703f3d522076fdacd81ba (patch)
treecaa85fe1518b5998cdb7c200b4d5d74c5576b300 /src
parentd17ac27a727a7a942aea6c5d8b549e4ce56f34a7 (diff)
parent0fb78eae34b870b9e5b942095d340f2aae49cd60 (diff)
Merge pull request #1295 from jgarzik/txn-retval
[FIX] Always check return values of TxnBegin() and TxnCommit()
Diffstat (limited to 'src')
-rw-r--r--src/bitcoinrpc.cpp6
-rw-r--r--src/main.cpp12
-rw-r--r--src/wallet.cpp3
3 files changed, 15 insertions, 6 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index e058978ebf..8e4361c92a 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -1037,7 +1037,8 @@ Value movecmd(const Array& params, bool fHelp)
strComment = params[4].get_str();
CWalletDB walletdb(pwalletMain->strWalletFile);
- walletdb.TxnBegin();
+ if (!walletdb.TxnBegin())
+ throw JSONRPCError(-20, "database error");
int64 nNow = GetAdjustedTime();
@@ -1059,7 +1060,8 @@ Value movecmd(const Array& params, bool fHelp)
credit.strComment = strComment;
walletdb.WriteAccountingEntry(credit);
- walletdb.TxnCommit();
+ if (!walletdb.TxnCommit())
+ throw JSONRPCError(-20, "database error");
return true;
}
diff --git a/src/main.cpp b/src/main.cpp
index e40acf6d32..6096ee3e60 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1514,7 +1514,9 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
{
uint256 hash = GetHash();
- txdb.TxnBegin();
+ if (!txdb.TxnBegin())
+ return error("SetBestChain() : TxnBegin failed");
+
if (pindexGenesisBlock == NULL && hash == hashGenesisBlock)
{
txdb.WriteHashBestChain(hash);
@@ -1563,7 +1565,10 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
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;
@@ -1621,7 +1626,8 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos)
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;
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 998909897f..96dc986edf 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -242,7 +242,8 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
if (fFileBacked)
{
pwalletdbEncryption = new CWalletDB(strWalletFile);
- pwalletdbEncryption->TxnBegin();
+ if (!pwalletdbEncryption->TxnBegin())
+ return false;
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
}