Skip to content

Commit

Permalink
Clang tidy and leakage fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ErakhtinB committed Nov 14, 2024
1 parent 22ca02a commit dd16b53
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions core/storage/rocksdb/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ namespace kagome::storage {
std::shared_ptr<RocksDb> &rocks_db,
const filesystem::path &ttl_migrated_path,
log::Logger &log) {
rocksdb::DB *db = nullptr;
rocksdb::DB *db_raw = nullptr;
std::vector<ColumnFamilyHandlePtr> column_family_handles;
auto status = rocksdb::DB::Open(options,
path.native(),
column_family_descriptors,
&column_family_handles,
&db);
&db_raw);
std::unique_ptr<rocksdb::DB> db(db_raw);
if (not status.ok()) {
SL_ERROR(log,
"Can't open old database in {}: {}",
Expand All @@ -205,7 +206,7 @@ namespace kagome::storage {
return status_as_error(status);
}

auto cleanup = [db, &column_family_handles, &log](int *) {
auto cleanup = [&db, &column_family_handles, &log](int *i) {
auto status = db->Flush(rocksdb::FlushOptions());
if (not status.ok()) {
SL_ERROR(log, "Can't flush database: {}", status.ToString());
Expand All @@ -222,11 +223,12 @@ namespace kagome::storage {
if (not status.ok()) {
SL_ERROR(log, "Can't close database: {}", status.ToString());
}
delete db;
db.reset();
delete i;
};

std::unique_ptr<int, decltype(cleanup)> defer_db(new int, cleanup);
rocksdb::DBWithTTL *db_with_ttl = nullptr;
rocksdb::DBWithTTL *db_with_ttl_raw = nullptr;
std::vector<ColumnFamilyHandlePtr> column_family_handles_with_ttl;
const auto ttl_path = path.parent_path() / "db_ttl";
std::error_code ec;
Expand All @@ -242,7 +244,7 @@ namespace kagome::storage {
ttl_path.native(),
column_family_descriptors,
&column_family_handles_with_ttl,
&db_with_ttl,
&db_with_ttl_raw,
ttls);
if (not status.ok()) {
SL_ERROR(log,
Expand All @@ -251,9 +253,10 @@ namespace kagome::storage {
status.ToString());
return status_as_error(status);
}
const auto ttl_cleanup = [db_with_ttl,
std::unique_ptr<rocksdb::DBWithTTL> db_with_ttl(db_with_ttl_raw);
const auto ttl_cleanup = [&db_with_ttl,
&column_family_handles_with_ttl,
&log](int *) {
&log](int *i) {
auto status = db_with_ttl->Flush(rocksdb::FlushOptions());
if (not status.ok()) {
SL_ERROR(log, "Can't flush ttl database: {}", status.ToString());
Expand All @@ -270,7 +273,8 @@ namespace kagome::storage {
if (not status.ok()) {
SL_ERROR(log, "Can't close ttl database: {}", status.ToString());
}
delete db_with_ttl;
db_with_ttl.reset();
delete i;
};
std::unique_ptr<int, decltype(ttl_cleanup)> defer_ttl(new int, ttl_cleanup);
for (std::size_t i = 0; i < column_family_handles.size(); ++i) {
Expand Down

0 comments on commit dd16b53

Please sign in to comment.