Skip to content

Commit

Permalink
Fix dispose pattern mentioned in Issue #7
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdy committed Oct 9, 2020
1 parent 4643781 commit a0be133
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,7 @@ public override Secret CopySecret()
public override void Close()
{
Debug.WriteLine("ProtectedMemorySecret.Close");
Dispose(true);
GC.SuppressFinalize(this);
}

public override void Dispose()
{
Debug.WriteLine("ProtectedMemorySecret.Dispose");
Dispose(true);
GC.SuppressFinalize(this);
Dispose();
}

internal static ProtectedMemorySecret FromCharArray(char[] sourceChars, IProtectedMemoryAllocator allocator, IConfiguration configuration)
Expand All @@ -166,7 +158,7 @@ internal static ProtectedMemorySecret FromCharArray(char[] sourceChars, IProtect
}
}

protected virtual void Dispose(bool disposing)
protected override void Dispose(bool disposing)
{
if (pointer != IntPtr.Zero)
{
Expand Down
8 changes: 7 additions & 1 deletion csharp/SecureMemory/SecureMemory/Secret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public virtual void WithSecretUtf8Chars(Action<char[]> actionWithSecret)

public abstract void Close();

public abstract void Dispose();
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected abstract void Dispose(bool disposing);
}
}

0 comments on commit a0be133

Please sign in to comment.