mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 22:36:05 +02:00
fix: Stop HasProcessExited from leaking process handles (#603)
Not closing process handles after using them. Every second. Smh. Imagine. Couldn't be me.
This commit is contained in:
@@ -28,6 +28,8 @@ namespace VRCX
|
|||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
public static extern bool GetExitCodeProcess(IntPtr hProcess, out uint lpExitCode);
|
public static extern bool GetExitCodeProcess(IntPtr hProcess, out uint lpExitCode);
|
||||||
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
|
public static extern bool CloseHandle(IntPtr hObject);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Flag that specifies the access rights to query limited information about a process.
|
/// Flag that specifies the access rights to query limited information about a process.
|
||||||
@@ -54,6 +56,9 @@ namespace VRCX
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool exited;
|
bool exited;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (!WinApi.GetExitCodeProcess(hProcess, out uint exitCode))
|
if (!WinApi.GetExitCodeProcess(hProcess, out uint exitCode))
|
||||||
{
|
{
|
||||||
throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
|
throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
|
||||||
@@ -61,6 +66,14 @@ namespace VRCX
|
|||||||
|
|
||||||
// Fun fact, If a program uses STILL_ACTIVE (259) as an exit code, GetExitCodeProcess will return 259, since it returns... the exit code. This would break this function.
|
// Fun fact, If a program uses STILL_ACTIVE (259) as an exit code, GetExitCodeProcess will return 259, since it returns... the exit code. This would break this function.
|
||||||
exited = exitCode != 259;
|
exited = exitCode != 259;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Imagine closing process handles.
|
||||||
|
WinApi.CloseHandle(hProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return exited;
|
return exited;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user