From 65310f3e5ed493dc48233f7854e973f6c2c6d5dd Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 18 Nov 2018 01:01:39 +0000 Subject: [PATCH] don't share SHA256CryptoServiceProvider (can be improved) --- OpenSim/Data/MySQL/MySQLXAssetData.cs | 9 +++------ OpenSim/Services/FSAssetService/FSAssetService.cs | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs index 9f9c9cf4fa..5c92be9e4e 100644 --- a/OpenSim/Data/MySQL/MySQLXAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs @@ -58,11 +58,6 @@ namespace OpenSim.Data.MySQL private bool m_enableCompression = false; private string m_connectionString; - /// - /// We can reuse this for all hashing since all methods are single-threaded through m_dbBLock - /// - private HashAlgorithm hasher = new SHA256CryptoServiceProvider(); - #region IPlugin Members public string Version { get { return "1.0.0.0"; } } @@ -250,7 +245,9 @@ namespace OpenSim.Data.MySQL } } - byte[] hash = hasher.ComputeHash(asset.Data); + byte[] hash; + using (HashAlgorithm hasher = new SHA256CryptoServiceProvider()) + hash = hasher.ComputeHash(asset.Data); // m_log.DebugFormat( // "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}", diff --git a/OpenSim/Services/FSAssetService/FSAssetService.cs b/OpenSim/Services/FSAssetService/FSAssetService.cs index 028dd0158f..2fb3e6ce90 100644 --- a/OpenSim/Services/FSAssetService/FSAssetService.cs +++ b/OpenSim/Services/FSAssetService/FSAssetService.cs @@ -52,7 +52,6 @@ namespace OpenSim.Services.FSAssetService private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); - static SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider(); static byte[] ToCString(string s) { @@ -357,7 +356,9 @@ namespace OpenSim.Services.FSAssetService string GetSHA256Hash(byte[] data) { - byte[] hash = SHA256.ComputeHash(data); + byte[] hash; + using (SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider()) + hash = SHA256.ComputeHash(data); return BitConverter.ToString(hash).Replace("-", String.Empty); }