From 7d7af80385f9f7eecac2f80bd9258c285d849158 Mon Sep 17 00:00:00 2001 From: Mert Emirimam <48881002+mertemr@users.noreply.github.com> Date: Fri, 3 Oct 2025 10:25:30 +0300 Subject: [PATCH] fix(Get-PESubsystem): Ensure resources are closed only if initialized. Fixes #6506 --- lib/core.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index b0e833c74b..bf281ec3c6 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -16,8 +16,8 @@ function Get-PESubsystem($filePath) { } catch { return -1 } finally { - $binaryReader.Close() - $fileStream.Close() + if ($null -ne $binaryReader) { $binaryReader.Close() } + if ($null -ne $fileStream) { $fileStream.Close() } } }