Skip to content

Commit

Permalink
Merge pull request #545 from pifil/master
Browse files Browse the repository at this point in the history
Fixed race condition in Disposable.Dispose()
  • Loading branch information
tillig committed Jul 9, 2014
2 parents 09f27e2 + 88ae777 commit bc3db14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Core/Source/Autofac/Features/OwnedInstances/Owned.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
var lt = _lifetime;
Interlocked.CompareExchange(ref _lifetime, null, lt);
var lt = Interlocked.Exchange(ref _lifetime, null);
if (lt != null)
{
_value = default(T);
Expand Down
13 changes: 6 additions & 7 deletions Core/Source/Autofac/Util/Disposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ public class Disposable : IDisposable
[SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification = "Dispose is implemented correctly, FxCop just doesn't see it.")]
public void Dispose()
{
var isDisposed = _isDisposed;
Interlocked.CompareExchange(ref _isDisposed, DisposedFlag, isDisposed);
if (isDisposed == 0)
{
Dispose(true);
GC.SuppressFinalize(this);
}
var wasDisposed = Interlocked.Exchange(ref _isDisposed, DisposedFlag);
if (wasDisposed == DisposedFlag)
return;

Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
Expand Down

0 comments on commit bc3db14

Please sign in to comment.