Skip to content

Commit

Permalink
Fix process leak in process enumeration. Dispose rejected ones. (#10186)
Browse files Browse the repository at this point in the history
This #10143 and fix is from there.

I considered nulling the array elements as I go, and then the tail,
to help the GC, but does it help actually? I suspect not.
  • Loading branch information
monojenkins authored and akoeplinger committed Aug 20, 2018
1 parent f236586 commit 94bb568
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mcs/class/System/System.Diagnostics/Process.cs
Expand Up @@ -508,9 +508,12 @@ public static Process[] GetProcessesByName(string processName, string machineNam
int size = 0;

for (int i = 0; i < processes.Length; i++) {
var process = processes[i];
try {
if (String.Compare (processName, processes[i].ProcessName, true) == 0)
processes [size++] = processes[i];
if (String.Compare (processName, process.ProcessName, true) == 0)
processes [size++] = process;
else
process.Dispose();
} catch (SystemException) {
/* The process might exit between GetProcesses_internal and GetProcessById */
}
Expand Down

0 comments on commit 94bb568

Please sign in to comment.