From 7837a536ebbce02f289f73b421f7b82fdd394874 Mon Sep 17 00:00:00 2001 From: Paul Higinbotham Date: Tue, 7 Apr 2020 14:31:04 -0700 Subject: [PATCH] Fix possible race that leaks PowerShell object dispose in `ForEach-Object -Parallel` (#12227) --- src/System.Management.Automation/engine/hostifaces/PSTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/hostifaces/PSTask.cs b/src/System.Management.Automation/engine/hostifaces/PSTask.cs index ab2dd6204b..0c63c2a0b7 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSTask.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSTask.cs @@ -867,7 +867,7 @@ namespace System.Management.Automation.PSTasks } task.StateChanged -= HandleTaskStateChangedDelegate; - if (!_stopping) + if (!_stopping || stateInfo.State != PSInvocationState.Stopped) { // StopAll disposes tasks. task.Dispose();