Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 6ba8417

Browse files
committed
One-time-use allocated blocks keep reference to source pool / Assert that a block is returned to it's source pool / Managed block are only returned to active Slabs
1 parent e54fa44 commit 6ba8417

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Microsoft.AspNet.Server.Kestrel/Infrastructure/MemoryPool2.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.Diagnostics;
34

45
namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
56
{
@@ -76,7 +77,7 @@ public MemoryPoolBlock2 Lease(int minimumSize = MaxPooledBlockLength)
7677
return MemoryPoolBlock2.Create(
7778
new ArraySegment<byte>(new byte[minimumSize]),
7879
dataPtr: IntPtr.Zero,
79-
pool: null,
80+
pool: this,
8081
slab: null);
8182
}
8283

@@ -137,11 +138,13 @@ private MemoryPoolBlock2 AllocateSlab()
137138
/// <param name="block">The block to return. It must have been acquired by calling Lease on the same memory pool instance.</param>
138139
public void Return(MemoryPoolBlock2 block)
139140
{
140-
if (block.Slab != null)
141+
Debug.Assert(block.Pool == this, "Returned block was leased from this pool");
142+
143+
if (block.Slab != null && block.Slab.IsActive)
141144
{
142145
block.Reset();
143146
_blocks.Enqueue(block);
144-
}
147+
}
145148
}
146149

147150
protected virtual void Dispose(bool disposing)

0 commit comments

Comments
 (0)