https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a80f803a2a1053835778a…
commit a80f803a2a1053835778a9da26fe85f907786efe
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Wed Aug 23 12:20:15 2017 +0000
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Oct 27 18:13:40 2018 +0200
[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 5714cec837..a2978a0f25 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 5aa2280182..ae0a30c241 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 928b6a7ea0..a82b04c291 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 f5e062b6cb..d9aa3b8469 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 306065f99a..a1744cc99e 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