From c1a7d45b66940ed1bc6d2f855f71976c1c2414ec Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 12 Mar 2021 23:29:42 -0800 Subject: [PATCH] Always clear the local buffer in ArrayBuffer - 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 5dbc5a158cb781..56413164232da6 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); } }