Skip to content

Commit 4d43f06

Browse files
committed
Fix unbounded memory growth.
Before, any call to resize would always double the size of the array.
1 parent 29fbed7 commit 4d43f06

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/MySqlConnector/Utilities/ResizableArray.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace MySqlConnector.Utilities
24
{
35
/// <summary>
@@ -14,7 +16,7 @@ internal sealed class ResizableArray<T>
1416
internal void DoResize(int length)
1517
{
1618
if (m_array == null || length > m_array.Length)
17-
System.Array.Resize(ref m_array, length);
19+
System.Array.Resize(ref m_array, Math.Max(length, Count * 2));
1820
}
1921

2022
T[] m_array;

src/MySqlConnector/Utilities/Utility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public static void Resize<T>(ref ResizableArray<T> resizableArray, int newLength
238238
{
239239
if (resizableArray == null)
240240
resizableArray = new ResizableArray<T>();
241-
resizableArray.DoResize(Math.Max(newLength, resizableArray.Count * 2));
241+
resizableArray.DoResize(newLength);
242242
}
243243

244244
public static TimeSpan ParseTimeSpan(ReadOnlySpan<byte> value)

0 commit comments

Comments
 (0)