diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-06 17:52:33 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-06 17:52:33 +0200 |
commit | 1803924a9474af03bf24bc00303c6373fdd05487 (patch) | |
tree | 25c77a9c4c8831d93ffe687d49a3aefaa5a184ca /common/storage_lmdb.cpp | |
parent | 141f945b8d6828372e8919e954fa2d8991aa1a6f (diff) | |
download | sink-1803924a9474af03bf24bc00303c6373fdd05487.tar.gz sink-1803924a9474af03bf24bc00303c6373fdd05487.zip |
Fixed a bunch of memory leaks.
Found with valgrind
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 3687594..2c0240d 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -103,6 +103,21 @@ Storage::NamedDatabase::NamedDatabase(NamedDatabase::Private *prv) : d(prv) | |||
103 | { | 103 | { |
104 | } | 104 | } |
105 | 105 | ||
106 | Storage::NamedDatabase::NamedDatabase(NamedDatabase &&other) : d(nullptr) | ||
107 | { | ||
108 | *this = std::move(other); | ||
109 | } | ||
110 | |||
111 | Storage::NamedDatabase &Storage::NamedDatabase::operator=(Storage::NamedDatabase &&other) | ||
112 | { | ||
113 | if (&other != this) { | ||
114 | delete d; | ||
115 | d = other.d; | ||
116 | other.d = nullptr; | ||
117 | } | ||
118 | return *this; | ||
119 | } | ||
120 | |||
106 | Storage::NamedDatabase::~NamedDatabase() | 121 | Storage::NamedDatabase::~NamedDatabase() |
107 | { | 122 | { |
108 | delete d; | 123 | delete d; |
@@ -398,6 +413,21 @@ Storage::Transaction::Transaction(Transaction::Private *prv) : d(prv) | |||
398 | d->startTransaction(); | 413 | d->startTransaction(); |
399 | } | 414 | } |
400 | 415 | ||
416 | Storage::Transaction::Transaction(Transaction &&other) : d(nullptr) | ||
417 | { | ||
418 | *this = std::move(other); | ||
419 | } | ||
420 | |||
421 | Storage::Transaction &Storage::Transaction::operator=(Storage::Transaction &&other) | ||
422 | { | ||
423 | if (&other != this) { | ||
424 | delete d; | ||
425 | d = other.d; | ||
426 | other.d = nullptr; | ||
427 | } | ||
428 | return *this; | ||
429 | } | ||
430 | |||
401 | Storage::Transaction::~Transaction() | 431 | Storage::Transaction::~Transaction() |
402 | { | 432 | { |
403 | if (d && d->transaction) { | 433 | if (d && d->transaction) { |
@@ -532,6 +562,7 @@ QList<QByteArray> Storage::Transaction::getDatabaseNames() const | |||
532 | Warning() << "Failed to get a value" << rc; | 562 | Warning() << "Failed to get a value" << rc; |
533 | } | 563 | } |
534 | } | 564 | } |
565 | mdb_cursor_close(cursor); | ||
535 | } else { | 566 | } else { |
536 | Warning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc)); | 567 | Warning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc)); |
537 | } | 568 | } |
@@ -594,6 +625,8 @@ Storage::Private::Private(const QString &s, const QString &n, AccessMode m) : st | |||
594 | } else { | 625 | } else { |
595 | // FIXME: dynamic resize | 626 | // FIXME: dynamic resize |
596 | const size_t dbSize = (size_t)10485760 * (size_t)8000; // 1MB * 8000 | 627 | const size_t dbSize = (size_t)10485760 * (size_t)8000; // 1MB * 8000 |
628 | // In order to run valgrind this size must be smaller than half your available RAM | ||
629 | // https://github.com/BVLC/caffe/issues/2404 | ||
597 | mdb_env_set_mapsize(env, dbSize); | 630 | mdb_env_set_mapsize(env, dbSize); |
598 | sEnvironments.insert(fullPath, env); | 631 | sEnvironments.insert(fullPath, env); |
599 | } | 632 | } |