From 102d1e856c7e0e553abeec937783da5debed73ad Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 28 Mar 2021 21:15:47 -0700 Subject: [PATCH] Always clear the local buffer in ArrayBuffer (#49573) - SslStream was holding onto a 4K byte[] after the handshake was complete. This was because the ArrayBuffer struct doesn't clear the local buffer field in dispose. This changes that. --- src/libraries/Common/src/System/Net/ArrayBuffer.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libraries/Common/src/System/Net/ArrayBuffer.cs b/src/libraries/Common/src/System/Net/ArrayBuffer.cs index 5dbc5a158cb78..56413164232da 100644 --- a/src/libraries/Common/src/System/Net/ArrayBuffer.cs +++ b/src/libraries/Common/src/System/Net/ArrayBuffer.cs @@ -41,15 +41,12 @@ public void Dispose() _activeStart = 0; _availableStart = 0; - if (_usePool) - { - byte[] array = _bytes; - _bytes = null!; + byte[] array = _bytes; + _bytes = null!; - if (array != null) - { - ArrayPool.Shared.Return(array); - } + if (_usePool && array != null) + { + ArrayPool.Shared.Return(array); } }