[SETUPLIB] Introduce and use a UnMapAndCloseFile() macro that calls UnMapFile() and...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Wed, 23 Aug 2017 12:20:15 +0000 (12:20 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 27 Oct 2018 16:13:40 +0000 (18:13 +0200)
svn path=/branches/setup_improvements/; revision=75651
svn path=/branches/setup_improvements/; revision=75657

base/setup/lib/bldrsup.c
base/setup/lib/filesup.h
base/setup/lib/osdetect.c
base/setup/lib/partlist.c
base/setup/lib/setuplib.c

index 5714cec..a2978a0 100644 (file)
@@ -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)
     {
index 5aa2280..ae0a30c 100644 (file)
@@ -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 */
index 928b6a7..a82b04c 100644 (file)
@@ -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;
 }
index f5e062b..d9aa3b8 100644 (file)
@@ -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.
index 306065f..a1744cc 100644 (file)
@@ -373,8 +373,7 @@ Quit:
     }
 
     /* Finally, unmap and close the file */
-    UnMapFile(SectionHandle, ViewBase);
-    NtClose(UnattendFileHandle);
+    UnMapAndCloseFile(UnattendFileHandle, SectionHandle, ViewBase);
 
     NtClose(FileHandle);
 #endif