Skip to content

Commit

Permalink
GuardedHeapAllocation.cs: Set the pointer to null in Dispose().
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-lucas6 committed Dec 14, 2024
1 parent a51a979 commit 91874d6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Geralt/Crypto/GuardedHeapAllocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public sealed class GuardedHeapAllocation : IDisposable
{
// A canary is placed before the data. However, this max size is artificial to limit memory usage
public static readonly int MaxSize = SecureMemory.PageSize - CANARY_SIZE;
private readonly IntPtr _pointer;
private readonly int _size;
private IntPtr _pointer;
private int _size;
private bool _disposed;

public GuardedHeapAllocation(int size)
Expand Down Expand Up @@ -52,6 +52,8 @@ public void Dispose()
if (_disposed) { throw new ObjectDisposedException(nameof(GuardedHeapAllocation)); }
// This calls sodium_mprotect_readwrite internally
sodium_free(_pointer);
_pointer = IntPtr.Zero;
_size = 0;
_disposed = true;
}
}

0 comments on commit 91874d6

Please sign in to comment.