Skip to content

Commit

Permalink
Update managed call site
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Jun 11, 2022
1 parent 9711a33 commit e36103c
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -184,10 +185,7 @@ public static unsafe long WorkingSet
private static unsafe string[] GetCommandLineArgsNative()
{
char* lpCmdLine = Interop.Kernel32.GetCommandLine();
if (lpCmdLine == null)
{
ThrowHelper.ThrowOutOfMemoryException();
}
Debug.Assert(lpCmdLine != null);

int numArgs = 0;
char** argvW = Interop.Shell32.CommandLineToArgv(lpCmdLine, &numArgs);
Expand All @@ -196,14 +194,19 @@ private static unsafe string[] GetCommandLineArgsNative()
ThrowHelper.ThrowOutOfMemoryException();
}

string[] result = new string[numArgs];
for (int i = 0; i < result.Length; i++)
try
{
string[] result = new string[numArgs];
for (int i = 0; i < result.Length; i++)
{
result[i] = new string(*(argvW + i));
}
return result;
}
finally
{
result[i] = new string(*(argvW + i));
Interop.Kernel32.LocalFree((nint)argvW);
}

Interop.Kernel32.LocalFree((nint)argvW);
return result;
}
}
}

0 comments on commit e36103c

Please sign in to comment.