aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-10-30 13:27:44 +0100
committerGitHub Enterprise <[email protected]>2025-10-30 13:27:44 +0100
commit4d5bfca81a54c1954dc82820d79227d6c146a0bb (patch)
tree2b784b3b28854d1dc6dff826db819252d58b6260 /src
parentfix minor memory leak in command line parsing (#619) (diff)
downloadzen-4d5bfca81a54c1954dc82820d79227d6c146a0bb.tar.xz
zen-4d5bfca81a54c1954dc82820d79227d6c146a0bb.zip
fix use-after-free in TEST_CASE("compactcas.threadedinsert") (#620)v5.7.8-pre1
Diffstat (limited to 'src')
-rw-r--r--src/zenstore/compactcas.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp
index 26af5b4b1..e1f17fbb9 100644
--- a/src/zenstore/compactcas.cpp
+++ b/src/zenstore/compactcas.cpp
@@ -1664,19 +1664,21 @@ TEST_CASE("compactcas.threadedinsert")
HashKeySet Deleted;
GcStats Stats;
GcStoreCompactor* Compactor =
- Pruner->RemoveUnreferencedData(Ctx, Stats, [&](std::span<IoHash> References) -> std::span<IoHash> {
- std::vector<IoHash> Unreferenced;
- HashKeySet Retain;
+ Pruner->RemoveUnreferencedData(Ctx, Stats, [&](const std::span<IoHash> References) -> std::span<IoHash> {
+ HashKeySet Retain;
Retain.AddHashesToSet(KeepHashes);
+
+ auto WriteIt = References.begin();
for (const IoHash& ChunkHash : References)
{
if (!Retain.ContainsHash(ChunkHash))
{
- Unreferenced.push_back(ChunkHash);
+ *WriteIt++ = ChunkHash;
}
}
- Deleted.AddHashesToSet(Unreferenced);
- return Unreferenced;
+ const std::span<IoHash> UnusedReferences = References.subspan(0, std::distance(References.begin(), WriteIt));
+ Deleted.AddHashesToSet(UnusedReferences);
+ return UnusedReferences;
});
if (Compactor)
{