aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-12-30 09:38:41 +0200
committerRiccardo Spagni <ric@spagni.net>2015-12-30 09:38:41 +0200
commitfd36eea6ddc23d223593adb235b8e13a58ac11ef (patch)
tree39b3e3ab7f14a3c7226d0b9b17377e7e8178403d /src/blockchain_db
parentMerge pull request #571 (diff)
parentMerge pull request #1 from LMDB/crash-fix (diff)
downloadmonero-fd36eea6ddc23d223593adb235b8e13a58ac11ef.tar.xz
Merge pull request #572
b39aae7 Tweak 45800a25e9374e63caaabba05c89585c86acd668 (hyc) 4a5a5ff blockchain: always stop the ioservice before returning (moneromooo-monero) 78b65cf db_lmdb: safety close db at exit (moneromooo-monero) 45800a2 db_lmdb: fix a strdup/delete[] mistmatch (moneromooo-monero)
Diffstat (limited to 'src/blockchain_db')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index d625e5a07..9555318a5 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -130,13 +130,16 @@ private:
template<>
struct MDB_val_copy<const char*>: public MDB_val
{
- MDB_val_copy(const char *s) :
- data(strdup(s))
+ MDB_val_copy(const char *s):
+ size(strlen(s)+1), // include the NUL, makes it easier for compares
+ data(new char[size])
{
- mv_size = strlen(s) + 1; // include the NUL, makes it easier for compares
+ mv_size = size;
mv_data = data.get();
+ memcpy(mv_data, s, size);
}
private:
+ size_t size;
std::unique_ptr<char[]> data;
};
@@ -923,6 +926,8 @@ BlockchainLMDB::~BlockchainLMDB()
// batch transaction shouldn't be active at this point. If it is, consider it aborted.
if (m_batch_active)
batch_abort();
+ if (m_open)
+ close();
}
BlockchainLMDB::BlockchainLMDB(bool batch_transactions)
@@ -1153,6 +1158,7 @@ void BlockchainLMDB::close()
// FIXME: not yet thread safe!!! Use with care.
mdb_env_close(m_env);
+ m_open = false;
}
void BlockchainLMDB::sync()