diff options
author | Stephen Toub <stoub@microsoft.com> | 2019-08-26 17:25:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-26 17:25:15 -0400 |
commit | 6f87fd8ded73f01f60df5af02eede184bacc6fe4 (patch) | |
tree | af9fe385909de4a2fcba66dd954eb5512b5c24a6 | |
parent | 654cd7e0d39c16fe3adec6f67a27eb3b1304c35d (diff) | |
download | coreclr-6f87fd8ded73f01f60df5af02eede184bacc6fe4.tar.gz coreclr-6f87fd8ded73f01f60df5af02eede184bacc6fe4.tar.bz2 coreclr-6f87fd8ded73f01f60df5af02eede184bacc6fe4.zip |
Do not use `AllocateUninitializedArray` in private array pools. (#26338) (#26366)
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.
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs b/src/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs index 054a38fc60..6dd3063258 100644 --- a/src/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs +++ b/src/System.Private.CoreLib/shared/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<T>(_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<T>(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<T>(_bufferLength); + buffer = new T[_bufferLength]; var log = ArrayPoolEventSource.Log; if (log.IsEnabled()) |