From e421481eb822c6d3d69e1deba7eab12d56ab77f7 Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Sun, 25 Aug 2019 19:14:06 -0700 Subject: [PATCH] Do not use `AllocateUninitializedArray` in private array pools. (dotnet/coreclr#26338) User may have extra expectations for the privatly owned array pools. For example there could be an expectation that array never contains negative numbers (since user never puts them there). Uninitialized allocations can break such expectations. Commit migrated from https://github.com/dotnet/coreclr/commit/c89fd6f88744bfee034e792906700c5a17e1b953 --- .../src/System/Buffers/ConfigurableArrayPool.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/ConfigurableArrayPool.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/ConfigurableArrayPool.cs index f7c2829..f24ddf4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/ConfigurableArrayPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/ConfigurableArrayPool.cs @@ -100,13 +100,13 @@ namespace System.Buffers // The pool was exhausted for this buffer size. Allocate a new buffer with a size corresponding // to the appropriate bucket. - buffer = GC.AllocateUninitializedArray(_buckets[index]._bufferLength); + buffer = new T[_buckets[index]._bufferLength]; } else { // The request was for a size too large for the pool. Allocate an array of exactly the requested length. // When it's returned to the pool, we'll simply throw it away. - buffer = GC.AllocateUninitializedArray(minimumLength); + buffer = new T[minimumLength]; } if (log.IsEnabled()) @@ -215,7 +215,7 @@ namespace System.Buffers // for that slot, in which case we should do so now. if (allocateBuffer) { - buffer = GC.AllocateUninitializedArray(_bufferLength); + buffer = new T[_bufferLength]; ArrayPoolEventSource log = ArrayPoolEventSource.Log; if (log.IsEnabled()) -- 2.7.4