From 91874d6f271a08059be4407297e7f39e3383ae0c Mon Sep 17 00:00:00 2001 From: Samuel Lucas <63159663+samuel-lucas6@users.noreply.github.com> Date: Sat, 14 Dec 2024 11:57:17 +0000 Subject: [PATCH] GuardedHeapAllocation.cs: Set the pointer to null in Dispose(). --- src/Geralt/Crypto/GuardedHeapAllocation.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Geralt/Crypto/GuardedHeapAllocation.cs b/src/Geralt/Crypto/GuardedHeapAllocation.cs index fc25ae5..b148288 100644 --- a/src/Geralt/Crypto/GuardedHeapAllocation.cs +++ b/src/Geralt/Crypto/GuardedHeapAllocation.cs @@ -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) @@ -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; } }