BaseTools/GenBootSector: Fix file handles not being closed
Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
@ -201,6 +201,7 @@ Return:
|
|||||||
//
|
//
|
||||||
// Only care about the disk.
|
// Only care about the disk.
|
||||||
//
|
//
|
||||||
|
CloseHandle(VolumeHandle);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else{
|
} else{
|
||||||
DriveInfo->DiskNumber = StorageDeviceNumber.DeviceNumber;
|
DriveInfo->DiskNumber = StorageDeviceNumber.DeviceNumber;
|
||||||
@ -437,8 +438,8 @@ ProcessBsOrMbr (
|
|||||||
BYTE DiskPartitionBackup[0x200] = {0};
|
BYTE DiskPartitionBackup[0x200] = {0};
|
||||||
DWORD BytesReturn;
|
DWORD BytesReturn;
|
||||||
INT DrvNumOffset;
|
INT DrvNumOffset;
|
||||||
HANDLE InputHandle;
|
HANDLE InputHandle = INVALID_HANDLE_VALUE;
|
||||||
HANDLE OutputHandle;
|
HANDLE OutputHandle = INVALID_HANDLE_VALUE;
|
||||||
ERROR_STATUS Status;
|
ERROR_STATUS Status;
|
||||||
DWORD InputDbrOffset;
|
DWORD InputDbrOffset;
|
||||||
DWORD OutputDbrOffset;
|
DWORD OutputDbrOffset;
|
||||||
@ -448,7 +449,7 @@ ProcessBsOrMbr (
|
|||||||
//
|
//
|
||||||
Status = GetFileHandle(InputInfo, ProcessMbr, &InputHandle, &InputDbrOffset);
|
Status = GetFileHandle(InputInfo, ProcessMbr, &InputHandle, &InputDbrOffset);
|
||||||
if (Status != ErrorSuccess) {
|
if (Status != ErrorSuccess) {
|
||||||
return Status;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -456,14 +457,15 @@ ProcessBsOrMbr (
|
|||||||
//
|
//
|
||||||
Status = GetFileHandle(OutputInfo, ProcessMbr, &OutputHandle, &OutputDbrOffset);
|
Status = GetFileHandle(OutputInfo, ProcessMbr, &OutputHandle, &OutputDbrOffset);
|
||||||
if (Status != ErrorSuccess) {
|
if (Status != ErrorSuccess) {
|
||||||
return Status;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read boot sector from source disk/file
|
// Read boot sector from source disk/file
|
||||||
//
|
//
|
||||||
if (!ReadFile (InputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
|
if (!ReadFile (InputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
|
||||||
return ErrorFileReadWrite;
|
Status = ErrorFileReadWrite;
|
||||||
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (InputInfo->Type == PathUsb) {
|
if (InputInfo->Type == PathUsb) {
|
||||||
@ -473,7 +475,8 @@ ProcessBsOrMbr (
|
|||||||
//
|
//
|
||||||
DrvNumOffset = GetDrvNumOffset (DiskPartition);
|
DrvNumOffset = GetDrvNumOffset (DiskPartition);
|
||||||
if (DrvNumOffset == -1) {
|
if (DrvNumOffset == -1) {
|
||||||
return ErrorFatType;
|
Status = ErrorFatType;
|
||||||
|
goto Done;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// Some legacy BIOS require 0x80 discarding MBR.
|
// Some legacy BIOS require 0x80 discarding MBR.
|
||||||
@ -495,7 +498,8 @@ ProcessBsOrMbr (
|
|||||||
// Use original partition table
|
// Use original partition table
|
||||||
//
|
//
|
||||||
if (!ReadFile (OutputHandle, DiskPartitionBackup, 0x200, &BytesReturn, NULL)) {
|
if (!ReadFile (OutputHandle, DiskPartitionBackup, 0x200, &BytesReturn, NULL)) {
|
||||||
return ErrorFileReadWrite;
|
Status = ErrorFileReadWrite;
|
||||||
|
goto Done;
|
||||||
}
|
}
|
||||||
memcpy (DiskPartition + 0x1BE, DiskPartitionBackup + 0x1BE, 0x40);
|
memcpy (DiskPartition + 0x1BE, DiskPartitionBackup + 0x1BE, 0x40);
|
||||||
SetFilePointer (OutputHandle, 0, NULL, FILE_BEGIN);
|
SetFilePointer (OutputHandle, 0, NULL, FILE_BEGIN);
|
||||||
@ -507,13 +511,19 @@ ProcessBsOrMbr (
|
|||||||
// Write boot sector to taget disk/file
|
// Write boot sector to taget disk/file
|
||||||
//
|
//
|
||||||
if (!WriteFile (OutputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
|
if (!WriteFile (OutputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
|
||||||
return ErrorFileReadWrite;
|
Status = ErrorFileReadWrite;
|
||||||
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle (InputHandle);
|
Done:
|
||||||
CloseHandle (OutputHandle);
|
if (InputHandle != INVALID_HANDLE_VALUE) {
|
||||||
|
CloseHandle (InputHandle);
|
||||||
|
}
|
||||||
|
if (OutputHandle != INVALID_HANDLE_VALUE) {
|
||||||
|
CloseHandle (OutputHandle);
|
||||||
|
}
|
||||||
|
|
||||||
return ErrorSuccess;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -631,6 +641,7 @@ GetPathInfo (
|
|||||||
fprintf (stderr, "error E2003: File was not provided!\n");
|
fprintf (stderr, "error E2003: File was not provided!\n");
|
||||||
return ErrorPath;
|
return ErrorPath;
|
||||||
}
|
}
|
||||||
|
fclose (f);
|
||||||
}
|
}
|
||||||
PathInfo->Type = PathFile;
|
PathInfo->Type = PathFile;
|
||||||
strcpy(PathInfo->PhysicalPath, PathInfo->Path);
|
strcpy(PathInfo->PhysicalPath, PathInfo->Path);
|
||||||
|
Reference in New Issue
Block a user