Skip to content

Commit 4a86a0a

Browse files
committed
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.
1 parent 1a9f9f7 commit 4a86a0a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/wallet/db.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ BerkeleyEnvironment::VerifyResult BerkeleyEnvironment::Verify(const std::string&
247247
return (fRecovered ? VerifyResult::RECOVER_OK : VerifyResult::RECOVER_FAIL);
248248
}
249249

250-
BerkeleyBatch::SafeDbt::SafeDbt(u_int32_t flags)
250+
BerkeleyBatch::SafeDbt::SafeDbt()
251251
{
252-
m_dbt.set_flags(flags);
252+
m_dbt.set_flags(DB_DBT_MALLOC);
253253
}
254254

255-
BerkeleyBatch::SafeDbt::SafeDbt(void *data, size_t size)
255+
BerkeleyBatch::SafeDbt::SafeDbt(void* data, size_t size)
256256
: m_dbt(data, size)
257257
{
258258
}

src/wallet/db.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,15 @@ class BerkeleyDatabase
170170
class BerkeleyBatch
171171
{
172172
/** RAII class that automatically cleanses its data on destruction */
173-
class SafeDbt final {
173+
class SafeDbt final
174+
{
174175
Dbt m_dbt;
175176

176177
public:
177-
// construct Dbt with data or flags
178-
SafeDbt(u_int32_t flags = 0);
179-
SafeDbt(void *data, size_t size);
178+
// construct Dbt with internally-managed data
179+
SafeDbt();
180+
// construct Dbt with provided data
181+
SafeDbt(void* data, size_t size);
180182
~SafeDbt();
181183

182184
// delegate to Dbt
@@ -227,7 +229,7 @@ class BerkeleyBatch
227229
SafeDbt datKey(ssKey.data(), ssKey.size());
228230

229231
// Read
230-
SafeDbt datValue(DB_DBT_MALLOC);
232+
SafeDbt datValue;
231233
int ret = pdb->get(activeTxn, datKey, datValue, 0);
232234
bool success = false;
233235
if (datValue.get_data() != nullptr) {
@@ -318,8 +320,8 @@ class BerkeleyBatch
318320
int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue)
319321
{
320322
// Read at cursor
321-
SafeDbt datKey(DB_DBT_MALLOC);
322-
SafeDbt datValue(DB_DBT_MALLOC);
323+
SafeDbt datKey;
324+
SafeDbt datValue;
323325
int ret = pcursor->get(datKey, datValue, DB_NEXT);
324326
if (ret != 0)
325327
return ret;

0 commit comments

Comments
 (0)