[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
This commit is contained in:
Hermès Bélusca-Maïto 2017-08-23 12:20:15 +00:00
parent 29fe31df1b
commit a80f803a2a
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 18 additions and 12 deletions

View 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)
{

View 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 */

View 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;
}

View 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.

View file

@ -373,8 +373,7 @@ Quit:
}
/* Finally, unmap and close the file */
UnMapFile(SectionHandle, ViewBase);
NtClose(UnattendFileHandle);
UnMapAndCloseFile(UnattendFileHandle, SectionHandle, ViewBase);
NtClose(FileHandle);
#endif