Skip to content

Commit 338068a

Browse files
committed
Fix null dereference bug in PopPowerShell()
1 parent fe914ac commit 338068a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
using System;
@@ -502,9 +502,11 @@ private void PopPowerShell(RunspaceChangeAction runspaceChangeAction = RunspaceC
502502
PowerShellContextFrame frame = _psFrameStack.Pop();
503503
try
504504
{
505-
// If we're changing runspace, make sure we move the handlers over
505+
// If we're changing runspace, make sure we move the handlers over.
506506
RunspaceFrame previousRunspaceFrame = _runspaceStack.Peek();
507-
if (previousRunspaceFrame.Runspace != CurrentPowerShell.Runspace)
507+
// Because the frame has been popped, we cannot rely on 'CurrentPowerShell.Runspace'
508+
// as it may be empty.
509+
if (previousRunspaceFrame.Runspace != frame.PowerShell.Runspace)
508510
{
509511
_runspaceStack.Pop();
510512
RunspaceFrame currentRunspaceFrame = _runspaceStack.Peek();

0 commit comments

Comments
 (0)