Skip to content

Commit

Permalink
Make SafeDbt DB_DBT_MALLOC on default initialization
Browse files Browse the repository at this point in the history
If we're constructing the SafeDbt without provided data, it is always malloced,
so that is the case we expose.

Also run clang-format.
  • Loading branch information
Empact committed Nov 25, 2018
1 parent 1a9f9f7 commit 4a86a0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/wallet/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
16 changes: 9 additions & 7 deletions src/wallet/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ class BerkeleyDatabase
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
Expand Down Expand Up @@ -227,7 +229,7 @@ class BerkeleyBatch
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) {
Expand Down Expand Up @@ -318,8 +320,8 @@ class BerkeleyBatch
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;
Expand Down

0 comments on commit 4a86a0a

Please sign in to comment.