From 0e72be02e034066120fe786216e2dfb06ad1f603 Mon Sep 17 00:00:00 2001 From: Luai Michlawi Date: Tue, 27 Aug 2019 12:43:44 +0200 Subject: [PATCH] Make RecentMessages thread safe --- src/RecentMessages.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/RecentMessages.cs b/src/RecentMessages.cs index 4deb36b..187b229 100644 --- a/src/RecentMessages.cs +++ b/src/RecentMessages.cs @@ -16,9 +16,6 @@ namespace Makaretu.Dns /// public class RecentMessages { - // MD5 is okay because the hash is not used for security. - HashAlgorithm hasher = MD5.Create(); - /// /// Recent messages. /// @@ -84,7 +81,11 @@ public int Prune() /// public string GetId(byte[] message) { - return Convert.ToBase64String(hasher.ComputeHash(message)); + // MD5 is okay because the hash is not used for security. + using (HashAlgorithm hasher = MD5.Create()) + { + return Convert.ToBase64String(hasher.ComputeHash(message)); + } } } }