Skip to content

Commit 0024531

Browse files
Use unique_ptr for dbw (CDBWrapper)
1 parent fa6d122 commit 0024531

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/test/dbwrapper_tests.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
125125
create_directories(ph);
126126

127127
// Set up a non-obfuscated wrapper to write some initial data.
128-
CDBWrapper* dbw = new CDBWrapper(ph, (1 << 10), false, false, false);
128+
std::unique_ptr<CDBWrapper> dbw = std::unique_ptr<CDBWrapper>(new CDBWrapper(ph, (1 << 10), false, false, false));
129129
char key = 'k';
130130
uint256 in = InsecureRand256();
131131
uint256 res;
@@ -135,8 +135,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
135135
BOOST_CHECK_EQUAL(res.ToString(), in.ToString());
136136

137137
// Call the destructor to free leveldb LOCK
138-
delete dbw;
139-
dbw = nullptr;
138+
dbw.reset();
140139

141140
// Now, set up another wrapper that wants to obfuscate the same directory
142141
CDBWrapper odbw(ph, (1 << 10), false, false, true);
@@ -167,7 +166,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
167166
create_directories(ph);
168167

169168
// Set up a non-obfuscated wrapper to write some initial data.
170-
CDBWrapper* dbw = new CDBWrapper(ph, (1 << 10), false, false, false);
169+
std::unique_ptr<CDBWrapper> dbw = std::unique_ptr<CDBWrapper>(new CDBWrapper(ph, (1 << 10), false, false, false));
171170
char key = 'k';
172171
uint256 in = InsecureRand256();
173172
uint256 res;
@@ -177,8 +176,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
177176
BOOST_CHECK_EQUAL(res.ToString(), in.ToString());
178177

179178
// Call the destructor to free leveldb LOCK
180-
delete dbw;
181-
dbw = nullptr;
179+
dbw.reset();
182180

183181
// Simulate a -reindex by wiping the existing data store
184182
CDBWrapper odbw(ph, (1 << 10), false, true, true);

0 commit comments

Comments
 (0)