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 Feb 7, 2025
1 parent dc5b25d commit a982355
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/bucket/BucketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,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 @@ -1608,9 +1615,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
2 changes: 1 addition & 1 deletion src/bucket/LiveBucketIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LiveBucketIndex::getPageSize(Config const& cfg, size_t bucketSize)
LiveBucketIndex::LiveBucketIndex(BucketManager& bm,
std::filesystem::path const& filename,
Hash const& hash, asio::io_context& ctx,
std::optional<SHA256>& hasher)
std::optional<SHA256>& hasher)
: mCacheHitMeter(bm.getCacheHitMeter())
, mCacheMissMeter(bm.getCacheMissMeter())
{
Expand Down

0 comments on commit a982355

Please sign in to comment.