Update src/SharpCompress/IO/PooledMemoryStream.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Adam Hathcock
2026-04-05 14:11:48 +01:00
committed by GitHub
parent 6b9a3f8b69
commit 5e7644bd18

View File

@@ -892,11 +892,10 @@ public sealed class PooledMemoryStream : MemoryStream
_contiguousBuffer = null;
}
for (var i = 0; i < _detachedExposedBuffers.Count; i++)
{
_arrayPool.Return(_detachedExposedBuffers[i]);
}
// Buffers tracked here have been exposed to callers. Returning them to the
// shared pool would allow unrelated code to rent and mutate arrays that may
// still be referenced after the stream is disposed, which breaks
// MemoryStream-compatible expectations for GetBuffer/TryGetBuffer.
_detachedExposedBuffers.Clear();
}