Skip to content

Commit

Permalink
Fix dangling reference in selfcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTyson committed Jan 30, 2025
1 parent b4dfd1e commit c0577fc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/bucket/BucketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,13 @@ BucketManager::scheduleVerifyReferencedBucketsWork(
releaseAssert(threadIsMain());
std::set<Hash> hashes = getAllReferencedBuckets(has);
std::vector<std::shared_ptr<BasicWork>> seq;

// Persist a map of indexes so we don't have dangling references in
// VerifyBucketsWork. We don't actually need to use the indexes created by
// VerifyBucketsWork here, so a throwaway static map is fine.
static std::map<int, std::unique_ptr<LiveBucketIndex const>> indexMap;

int i = 0;
for (auto const& h : hashes)
{
if (isZero(h))
Expand All @@ -1592,9 +1599,11 @@ BucketManager::scheduleVerifyReferencedBucketsWork(
throw std::runtime_error(fmt::format(
FMT_STRING("Missing referenced bucket {}"), binToHex(h)));
}
std::unique_ptr<LiveBucketIndex const> index;

auto [indexIter, _] = indexMap.emplace(i++, nullptr);
seq.emplace_back(std::make_shared<VerifyBucketWork>(
mApp, b->getFilename().string(), b->getHash(), index, nullptr));
mApp, b->getFilename().string(), b->getHash(), indexIter->second,
nullptr));
}
return mApp.getWorkScheduler().scheduleWork<WorkSequence>(
"verify-referenced-buckets", seq);
Expand Down

0 comments on commit c0577fc

Please sign in to comment.