8000 fixed use of the process handle after Process instance goes out of sc… · spsforks/pythonnet-pythonnet@4241493 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4241493

Browse files
authored
fixed use of the process handle after Process instance goes out of scope (pythonnet#1940)
fixes pythonnet#1939
1 parent bd48dc1 commit 4241493

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/runtime/Native/LibraryLoader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ public IntPtr GetFunction(IntPtr hModule, string procedureName)
137137

138138
static IntPtr[] GetAllModules()
139139
{
140-
var self = Process.GetCurrentProcess().Handle;
140+
using var self = Process.GetCurrentProcess();
141141

142142
uint bytes = 0;
143143
var result = new IntPtr[0];
144-
if (!EnumProcessModules(self, result, bytes, out var needsBytes))
144+
if (!EnumProcessModules(self.Handle, result, bytes, out var needsBytes))
145145
throw new Win32Exception();
146146
while (bytes < needsBytes)
147147
{
148148
bytes = needsBytes;
149149
result = new IntPtr[bytes / IntPtr.Size];
150-
if (!EnumProcessModules(self, result, bytes, out needsBytes))
150+
if (!EnumProcessModules(self.Handle, result, bytes, out needsBytes))
151151
throw new Win32Exception();
152152
}
153153
return result.Take((int)(needsBytes / IntPtr.Size)).ToArray();

0 commit comments

Comments
 (0)
0