Skip to content
Merged
Changes from all commits
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
fixed use of the process handle after Process instance goes out of scope
fixes #1939
  • Loading branch information
lostmsu committed Sep 15, 2022
commit 86b9811f74b5f888569d67b3bbd69858332d3737
6 changes: 3 additions & 3 deletions src/runtime/Native/LibraryLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ public IntPtr GetFunction(IntPtr hModule, string procedureName)

static IntPtr[] GetAllModules()
{
var self = Process.GetCurrentProcess().Handle;
using var self = Process.GetCurrentProcess();

uint bytes = 0;
var result = new IntPtr[0];
if (!EnumProcessModules(self, result, bytes, out var needsBytes))
if (!EnumProcessModules(self.Handle, result, bytes, out var needsBytes))
throw new Win32Exception();
while (bytes < needsBytes)
{
bytes = needsBytes;
result = new IntPtr[bytes / IntPtr.Size];
if (!EnumProcessModules(self, result, bytes, out needsBytes))
if (!EnumProcessModules(self.Handle, result, bytes, out needsBytes))
throw new Win32Exception();
}
return result.Take((int)(needsBytes / IntPtr.Size)).ToArray();
Expand Down