diff options
author | Ben Woosley <ben.woosley@gmail.com> | 2018-11-24 20:49:08 -0600 |
---|---|---|
committer | Ben Woosley <ben.woosley@gmail.com> | 2018-11-24 21:05:48 -0600 |
commit | 4a86a0acd9ac3ca392f0584a5fd079a856e5e4ba (patch) | |
tree | 33c6ddfc06796a2b7e5bb98da1076969c02c5080 | |
parent | 1a9f9f7e5e2e73fb832f5b96ad7e9e57954f3f3c (diff) |
Make SafeDbt DB_DBT_MALLOC on default initialization
If we're constructing the SafeDbt without provided data, it is always malloced,
so that is the case we expose.
Also run clang-format.
-rw-r--r-- | src/wallet/db.cpp | 6 | ||||
-rw-r--r-- | src/wallet/db.h | 16 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 9bac3c49cc..b3ae3b92ab 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -247,12 +247,12 @@ BerkeleyEnvironment::VerifyResult BerkeleyEnvironment::Verify(const std::string& return (fRecovered ? VerifyResult::RECOVER_OK : VerifyResult::RECOVER_FAIL); } -BerkeleyBatch::SafeDbt::SafeDbt(u_int32_t flags) +BerkeleyBatch::SafeDbt::SafeDbt() { - m_dbt.set_flags(flags); + m_dbt.set_flags(DB_DBT_MALLOC); } -BerkeleyBatch::SafeDbt::SafeDbt(void *data, size_t size) +BerkeleyBatch::SafeDbt::SafeDbt(void* data, size_t size) : m_dbt(data, size) { } diff --git a/src/wallet/db.h b/src/wallet/db.h index 73cbff98fb..25e1cdafa5 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -170,13 +170,15 @@ private: class BerkeleyBatch { /** RAII class that automatically cleanses its data on destruction */ - class SafeDbt final { + class SafeDbt final + { Dbt m_dbt; public: - // construct Dbt with data or flags - SafeDbt(u_int32_t flags = 0); - SafeDbt(void *data, size_t size); + // construct Dbt with internally-managed data + SafeDbt(); + // construct Dbt with provided data + SafeDbt(void* data, size_t size); ~SafeDbt(); // delegate to Dbt @@ -227,7 +229,7 @@ public: SafeDbt datKey(ssKey.data(), ssKey.size()); // Read - SafeDbt datValue(DB_DBT_MALLOC); + SafeDbt datValue; int ret = pdb->get(activeTxn, datKey, datValue, 0); bool success = false; if (datValue.get_data() != nullptr) { @@ -318,8 +320,8 @@ public: int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue) { // Read at cursor - SafeDbt datKey(DB_DBT_MALLOC); - SafeDbt datValue(DB_DBT_MALLOC); + SafeDbt datKey; + SafeDbt datValue; int ret = pcursor->get(datKey, datValue, DB_NEXT); if (ret != 0) return ret; |