Skip to content

Commit dbd3faa

Browse files
authored
Merge pull request #137 from cairoshell/fix-hproc-leak
Fix process handle leak (#136)
2 parents 5c9dfa7 + f743a76 commit dbd3faa

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/ManagedShell.Common/Helpers/ShellHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ public static string GetPathForWindowHandle(IntPtr hWnd)
340340
// get path
341341
int len = outFileName.Capacity;
342342
QueryFullProcessImageName(hProc, 0, outFileName, ref len);
343+
CloseHandle(hProc);
343344
}
344345

345346
return outFileName.ToString();
@@ -403,7 +404,7 @@ public static string GetAppUserModelIdForHandle(IntPtr hWnd)
403404
StringBuilder outAumid = new StringBuilder((int)len);
404405

405406
GetApplicationUserModelId(hProcess, ref len, outAumid);
406-
CloseHandle((int)hProcess);
407+
CloseHandle(hProcess);
407408

408409
if (outAumid.Length > 0)
409410
{

src/ManagedShell.Interop/NativeMethods.Kernel32.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)]
7171
[DllImport(Kernel32_DllName)]
7272
public static extern Int32 CloseHandle(Int32 Handle);
7373

74+
[DllImport(Kernel32_DllName)]
75+
public static extern bool CloseHandle(IntPtr Handle);
76+
7477
[DllImport(Kernel32_DllName, SetLastError = true, CallingConvention = CallingConvention.Winapi)]
7578
[return: MarshalAs(UnmanagedType.Bool)]
7679
public static extern bool IsWow64Process(

src/ManagedShell.WindowsTray/ExplorerTrayService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private void GetTrayItems()
106106

107107
VirtualFreeEx(hProcess, hBuffer, 0, AllocationType.Release);
108108

109-
CloseHandle((int)hProcess);
109+
CloseHandle(hProcess);
110110
}
111111

112112
private IntPtr FindExplorerTrayToolbarHwnd()

0 commit comments

Comments
 (0)