Skip to content

Commit 6226950

Browse files
Delete leveldb::DB object on error (#1204)
leveldb do not manage DB objects lifetime by itself. So in case of error or early return from the Open routine leveldb::DB object should be removed explicitly Relates-To: OLPSUP-14088 Signed-off-by: Andrey Kashcheev <[email protected]>
1 parent 0ee679c commit 6226950

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

olp-cpp-sdk-core/src/cache/DiskCache.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,14 @@ OpenResult DiskCache::Open(const std::string& data_path,
268268
error_ = NoError{};
269269
}
270270

271-
if (is_read_only && !CheckCompactionFinished(*db)) {
271+
std::unique_ptr<leveldb::DB> tmp_db{db};
272+
273+
if (is_read_only && !CheckCompactionFinished(*tmp_db)) {
272274
OLP_SDK_LOG_ERROR(kLogTag, "Open: interrupted compaction detected");
273275
return OpenResult::Corrupted;
274276
}
275277

276-
database_.reset(db);
278+
database_.swap(tmp_db);
277279

278280
return OpenResult::Success;
279281
}

0 commit comments

Comments
 (0)