Skip to content

Commit ae52d7c

Browse files
Address review: take the runspace lock on both dispose paths
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
1 parent c4321d8 commit ae52d7c

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

Engine/CommandInfoCache.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,23 @@ public void Dispose()
5757

5858
protected virtual void Dispose(bool disposing)
5959
{
60-
if ( disposed )
60+
// Always take the lock, also on the finalizer path, so that 'disposed' is never
61+
// published without the runspace being disposed along with it and so that the runspace
62+
// cannot be disposed while a lookup is in flight.
63+
lock (_runspaceLock)
6164
{
62-
return;
63-
}
65+
if ( disposed )
66+
{
67+
return;
68+
}
6469

65-
if ( disposing )
66-
{
67-
// Take the lock so that the runspace is not disposed while a lookup is in flight.
68-
lock (_runspaceLock)
70+
disposed = true;
71+
72+
if ( disposing )
6973
{
70-
disposed = true;
7174
_runspace.Dispose();
7275
}
73-
74-
return;
7576
}
76-
77-
disposed = true;
7877
}
7978

8079
/// <summary>

0 commit comments

Comments
 (0)