diff --git a/db/version_set.cc b/db/version_set.cc index 794060d8a3..051fe2ef7f 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -50,7 +50,6 @@ #include "table/two_level_iterator.h" #include "test_util/sync_point.h" #include "util/coding.h" -#include "util/defer.h" #include "util/stop_watch.h" #include "util/string_util.h" #include "util/user_comparator_wrapper.h" @@ -3614,14 +3613,6 @@ Status VersionSet::ProcessManifestWrites( autovector versions; autovector mutable_cf_options_ptrs; std::vector> builder_guards; - Status s; - Defer defer([&s, &versions]() { - if (!s.ok()) { - for (auto v : versions) { - delete v; - } - } - }); if (first_writer.edit_list.front()->IsColumnFamilyManipulation()) { // No group commits for column family add or drop @@ -3707,8 +3698,12 @@ Status VersionSet::ProcessManifestWrites( } else if (group_start != std::numeric_limits::max()) { group_start = std::numeric_limits::max(); } - s = LogAndApplyHelper(last_writer->cfd, builder, e, mu); + Status s = LogAndApplyHelper(last_writer->cfd, builder, e, mu); if (!s.ok()) { + // free up the allocated memory + for (auto v : versions) { + delete v; + } return s; } batch_edits.push_back(e); @@ -3718,8 +3713,12 @@ Status VersionSet::ProcessManifestWrites( assert(!builder_guards.empty() && builder_guards.size() == versions.size()); auto* builder = builder_guards[i]->version_builder(); - s = builder->SaveTo(versions[i]->storage_info()); + Status s = builder->SaveTo(versions[i]->storage_info()); if (!s.ok()) { + // free up the allocated memory + for (auto v : versions) { + delete v; + } return s; } } @@ -3762,6 +3761,7 @@ Status VersionSet::ProcessManifestWrites( #endif // NDEBUG uint64_t new_manifest_file_size = 0; + Status s; assert(pending_manifest_file_number_ == 0); if (!descriptor_log_ || @@ -3968,6 +3968,9 @@ Status VersionSet::ProcessManifestWrites( ROCKS_LOG_ERROR(db_options_->info_log, "Error in committing version edit to MANIFEST: %s", version_edits.c_str()); + for (auto v : versions) { + delete v; + } // If manifest append failed for whatever reason, the file could be // corrupted. So we need to force the next version update to start a // new manifest file.