From a80f803a2a1053835778a9da26fe85f907786efe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Wed, 23 Aug 2017 12:20:15 +0000 Subject: [PATCH] [SETUPLIB] Introduce and use a UnMapAndCloseFile() macro that calls UnMapFile() and NtClose() on handles returned by the OpenAndMapFile() function. svn path=/branches/setup_improvements/; revision=75651 svn path=/branches/setup_improvements/; revision=75657 --- base/setup/lib/bldrsup.c | 10 ++++++---- base/setup/lib/filesup.h | 6 ++++++ base/setup/lib/osdetect.c | 9 ++++----- base/setup/lib/partlist.c | 2 +- base/setup/lib/setuplib.c | 3 +-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/base/setup/lib/bldrsup.c b/base/setup/lib/bldrsup.c index 5714cec8373..a2978a0f257 100644 --- a/base/setup/lib/bldrsup.c +++ b/base/setup/lib/bldrsup.c @@ -461,8 +461,9 @@ OpenIniBootLoaderStore( DPRINT1("IniCacheLoadFromMemory() failed (Status 0x%08lx)\n", Status); /* Finally, unmap and close the file */ - UnMapFile(BootStore->SectionHandle, BootStore->ViewBase); - NtClose(BootStore->FileHandle); + UnMapAndCloseFile(BootStore->FileHandle, + BootStore->SectionHandle, + BootStore->ViewBase); RtlFreeHeap(ProcessHeap, 0, BootStore); return Status; @@ -715,8 +716,9 @@ Quit: if (BootStore->SectionHandle) { /* Finally, unmap and close the file */ - UnMapFile(BootStore->SectionHandle, BootStore->ViewBase); - NtClose(BootStore->FileHandle); + UnMapAndCloseFile(BootStore->FileHandle, + BootStore->SectionHandle, + BootStore->ViewBase); } else // if (BootStore->FileHandle) { diff --git a/base/setup/lib/filesup.h b/base/setup/lib/filesup.h index 5aa22801822..ae0a30c2416 100644 --- a/base/setup/lib/filesup.h +++ b/base/setup/lib/filesup.h @@ -100,4 +100,10 @@ UnMapFile( IN HANDLE SectionHandle, IN PVOID BaseAddress); +#define UnMapAndCloseFile(FileHandle, SectionHandle, BaseAddress) \ +do { \ + UnMapFile((SectionHandle), (BaseAddress)); \ + NtClose(FileHandle); \ +} while (0) + /* EOF */ diff --git a/base/setup/lib/osdetect.c b/base/setup/lib/osdetect.c index 928b6a7ea0c..a82b04c291f 100644 --- a/base/setup/lib/osdetect.c +++ b/base/setup/lib/osdetect.c @@ -284,7 +284,7 @@ CheckForValidPEAndVendor( { DPRINT1("File '%S' does not seem to be a valid PE, bail out\n", PathNameToFile); Status = STATUS_INVALID_IMAGE_FORMAT; - goto UnmapFile; + goto UnmapCloseFile; } /* @@ -295,7 +295,7 @@ CheckForValidPEAndVendor( if (!NT_SUCCESS(Status)) { DPRINT1("Failed to get version resource for file '%S', Status 0x%08lx\n", PathNameToFile, Status); - goto UnmapFile; + goto UnmapCloseFile; } Status = NtVerQueryValue(VersionBuffer, L"\\VarFileInfo\\Translation", &pvData, &BufLen); @@ -333,10 +333,9 @@ CheckForValidPEAndVendor( if (!NT_SUCCESS(Status)) DPRINT1("No version vendor found for file '%S'\n", PathNameToFile); -UnmapFile: +UnmapCloseFile: /* Finally, unmap and close the file */ - UnMapFile(SectionHandle, ViewBase); - NtClose(FileHandle); + UnMapAndCloseFile(FileHandle, SectionHandle, ViewBase); return Success; } diff --git a/base/setup/lib/partlist.c b/base/setup/lib/partlist.c index f5e062b6cb5..d9aa3b84698 100644 --- a/base/setup/lib/partlist.c +++ b/base/setup/lib/partlist.c @@ -841,7 +841,7 @@ SetDiskSignature( continue; } - /* check if the signature already exist */ + /* Check if the signature already exist */ /* FIXME: * Check also signatures from disks, which are * not visible (bootable) by the bios. diff --git a/base/setup/lib/setuplib.c b/base/setup/lib/setuplib.c index 306065f99a7..a1744cc99ec 100644 --- a/base/setup/lib/setuplib.c +++ b/base/setup/lib/setuplib.c @@ -373,8 +373,7 @@ Quit: } /* Finally, unmap and close the file */ - UnMapFile(SectionHandle, ViewBase); - NtClose(UnattendFileHandle); + UnMapAndCloseFile(UnattendFileHandle, SectionHandle, ViewBase); NtClose(FileHandle); #endif -- 2.17.1