diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetHash.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetHash.cs index d55c983913..336c4829d4 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetHash.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetHash.cs @@ -121,10 +121,11 @@ namespace Microsoft.PowerShell.Commands { byte[] bytehash = null; String hash = null; + Stream openfilestream = null; try { - Stream openfilestream = File.OpenRead(path); + openfilestream = File.OpenRead(path); bytehash = hasher.ComputeHash(openfilestream); hash = BitConverter.ToString(bytehash).Replace("-",""); @@ -138,6 +139,10 @@ namespace Microsoft.PowerShell.Commands path); WriteError(errorRecord); } + finally + { + openfilestream?.Dispose(); + } } }