Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
polishing
  • Loading branch information
adamsitnik committed Aug 15, 2021
commit 6b4f2bcd7b09229ca804736b05ad94331923ae5b
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ private static ProcessModuleCollection GetModules(int processId, bool firstModul

var modules = new ProcessModuleCollection(firstModuleOnly ? 1 : modulesCount);

const int startLength =
const int StartLength =
#if DEBUG
1; // in debug, validate ArrayPool growth
#else
Interop.Kernel32.MAX_PATH;
#endif
char[]? chars = ArrayPool<char>.Shared.Rent(startLength);
char[]? chars = ArrayPool<char>.Shared.Rent(StartLength);
try
{
for (int i = 0; i < modulesCount; i++)
Expand All @@ -157,7 +157,7 @@ private static ProcessModuleCollection GetModules(int processId, bool firstModul
Interop.Kernel32.NtModuleInfo ntModuleInfo;
if (!Interop.Kernel32.GetModuleInformation(processHandle, moduleHandle, out ntModuleInfo))
{
HandleLastWin32Error(null);
HandleLastWin32Error();
continue;
}

Expand All @@ -178,7 +178,8 @@ private static ProcessModuleCollection GetModules(int processId, bool firstModul

if (length == 0)
{
HandleLastWin32Error(module);
module.Dispose();
HandleLastWin32Error();
continue;
}

Expand All @@ -193,7 +194,8 @@ private static ProcessModuleCollection GetModules(int processId, bool firstModul

if (length == 0)
{
HandleLastWin32Error(module);
module.Dispose();
HandleLastWin32Error();
continue;
}

Expand Down Expand Up @@ -246,7 +248,7 @@ private static void EnumProcessModulesUntilSuccess(SafeProcessHandle processHand
}
}

private static void HandleLastWin32Error(ProcessModule? processModule)
private static void HandleLastWin32Error()
{
int lastError = Marshal.GetLastWin32Error();
switch (lastError)
Expand All @@ -258,7 +260,6 @@ private static void HandleLastWin32Error(ProcessModule? processModule)
// move on.
break;
default:
processModule?.Dispose();
throw new Win32Exception(lastError);
}
}
Expand Down