Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a5cc306

Browse files
tmdseerhardt
authored andcommitted
Sync Interop.GetCwd with coreclr
1 parent bd4859e commit a5cc306

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Common/src/Interop/Unix/System.Native/Interop.GetCwd.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Buffers;
67
using System.Runtime.InteropServices;
78

89
internal static partial class Interop
@@ -29,15 +30,22 @@ internal static unsafe string GetCwd()
2930
do
3031
{
3132
checked { bufferSize *= 2; }
32-
var buf = new byte[bufferSize];
33-
fixed (byte* ptr = &buf[0])
33+
byte[] buf = ArrayPool<byte>.Shared.Rent(bufferSize);
34+
try
3435
{
35-
result = GetCwdHelper(ptr, buf.Length);
36-
if (result != null)
36+
fixed (byte* ptr = &buf[0])
3737
{
38-
return result;
38+
result = GetCwdHelper(ptr, buf.Length);
39+
if (result != null)
40+
{
41+
return result;
42+
}
3943
}
4044
}
45+
finally
46+
{
47+
ArrayPool<byte>.Shared.Return(buf);
48+
}
4149
}
4250
while (true);
4351
}
@@ -63,4 +71,4 @@ private static unsafe string GetCwdHelper(byte* ptr, int bufferSize)
6371
throw Interop.GetExceptionForIoErrno(errorInfo);
6472
}
6573
}
66-
}
74+
}

0 commit comments

Comments
 (0)