[System] Fix handle leak in Process::GetProcess.
[mono.git] / mcs / class / System / System.Diagnostics / Process.cs
index 59544083c38a96a0a74dbbf4769910302b163f83..b038095093c5b31d60332cd4de3021c0b11e0787 100644 (file)
@@ -482,7 +482,8 @@ namespace System.Diagnostics
                        if (proc == IntPtr.Zero)
                                throw new ArgumentException ("Can't find process with ID " + processId.ToString ());
 
-                       return (new Process (new SafeProcessHandle (proc, false), processId));
+                       /* The handle returned by GetProcess_internal is owned by its caller, so we must pass true to SafeProcessHandle */
+                       return (new Process (new SafeProcessHandle (proc, true), processId));
                }
 
                public static Process[] GetProcessesByName(string processName, string machineName)