Skip to content

Commit c7575c2

Browse files
fix: dispose SHA1 instance in Caching.hashString; use SHA1.HashData on .NET 5+
On netstandard2.0, SHA1.Create() returns a HashAlgorithm (IDisposable) that was never disposed — a small but genuine resource leak. On .NET 5+, use the static SHA1.HashData(byte[]) method which avoids creating a disposable instance entirely and is the idiomatic modern API. On netstandard2.0, wrap the instance in 'use' to ensure deterministic disposal. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a1ee141 commit c7575c2

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/FSharp.Data.Runtime.Utilities/Caching.fs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@ let createInMemoryCache (expiration: TimeSpan) =
5555
/// Get hash code of a string - used to determine cache file
5656
let private hashString (plainText: string) =
5757
let plainTextBytes = Encoding.UTF8.GetBytes(plainText)
58-
let hashBytes = SHA1.Create().ComputeHash(plainTextBytes)
58+
59+
let hashBytes =
60+
#if NET5_0_OR_GREATER
61+
SHA1.HashData(plainTextBytes)
62+
#else
63+
use sha1 = SHA1.Create()
64+
sha1.ComputeHash(plainTextBytes)
65+
#endif
66+
5967
let s = Convert.ToBase64String(hashBytes)
6068
s.Replace("ab", "abab").Replace("\\", "ab")
6169

0 commit comments

Comments
 (0)