summaryrefslogtreecommitdiff
path: root/BaseTools
diff options
context:
space:
mode:
authorHao Wu <hao.a.wu@intel.com>2016-10-11 15:46:18 +0800
committerHao Wu <hao.a.wu@intel.com>2016-11-08 16:37:57 +0800
commit197b8f261b45c6900c2dc8e650e82e606184d50f (patch)
tree4df2676f3af0fa4c37ca09c810afe12341f6adb3 /BaseTools
parent1e124de0188e6e3ed557500cc429cf7a756786d3 (diff)
downloadedk2-platforms-197b8f261b45c6900c2dc8e650e82e606184d50f.tar.xz
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>
Diffstat (limited to 'BaseTools')
-rw-r--r--BaseTools/Source/C/GenBootSector/GenBootSector.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/BaseTools/Source/C/GenBootSector/GenBootSector.c b/BaseTools/Source/C/GenBootSector/GenBootSector.c
index 213e1b9722..3908c589af 100644
--- a/BaseTools/Source/C/GenBootSector/GenBootSector.c
+++ b/BaseTools/Source/C/GenBootSector/GenBootSector.c
@@ -201,6 +201,7 @@ Return:
//
// Only care about the disk.
//
+ CloseHandle(VolumeHandle);
return FALSE;
} else{
DriveInfo->DiskNumber = StorageDeviceNumber.DeviceNumber;
@@ -437,8 +438,8 @@ ProcessBsOrMbr (
BYTE DiskPartitionBackup[0x200] = {0};
DWORD BytesReturn;
INT DrvNumOffset;
- HANDLE InputHandle;
- HANDLE OutputHandle;
+ HANDLE InputHandle = INVALID_HANDLE_VALUE;
+ HANDLE OutputHandle = INVALID_HANDLE_VALUE;
ERROR_STATUS Status;
DWORD InputDbrOffset;
DWORD OutputDbrOffset;
@@ -448,7 +449,7 @@ ProcessBsOrMbr (
//
Status = GetFileHandle(InputInfo, ProcessMbr, &InputHandle, &InputDbrOffset);
if (Status != ErrorSuccess) {
- return Status;
+ goto Done;
}
//
@@ -456,14 +457,15 @@ ProcessBsOrMbr (
//
Status = GetFileHandle(OutputInfo, ProcessMbr, &OutputHandle, &OutputDbrOffset);
if (Status != ErrorSuccess) {
- return Status;
+ goto Done;
}
//
// Read boot sector from source disk/file
//
if (!ReadFile (InputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
- return ErrorFileReadWrite;
+ Status = ErrorFileReadWrite;
+ goto Done;
}
if (InputInfo->Type == PathUsb) {
@@ -473,7 +475,8 @@ ProcessBsOrMbr (
//
DrvNumOffset = GetDrvNumOffset (DiskPartition);
if (DrvNumOffset == -1) {
- return ErrorFatType;
+ Status = ErrorFatType;
+ goto Done;
}
//
// Some legacy BIOS require 0x80 discarding MBR.
@@ -495,7 +498,8 @@ ProcessBsOrMbr (
// Use original partition table
//
if (!ReadFile (OutputHandle, DiskPartitionBackup, 0x200, &BytesReturn, NULL)) {
- return ErrorFileReadWrite;
+ Status = ErrorFileReadWrite;
+ goto Done;
}
memcpy (DiskPartition + 0x1BE, DiskPartitionBackup + 0x1BE, 0x40);
SetFilePointer (OutputHandle, 0, NULL, FILE_BEGIN);
@@ -507,13 +511,19 @@ ProcessBsOrMbr (
// Write boot sector to taget disk/file
//
if (!WriteFile (OutputHandle, DiskPartition, 0x200, &BytesReturn, NULL)) {
- return ErrorFileReadWrite;
+ Status = ErrorFileReadWrite;
+ goto Done;
}
- CloseHandle (InputHandle);
- CloseHandle (OutputHandle);
+Done:
+ if (InputHandle != INVALID_HANDLE_VALUE) {
+ CloseHandle (InputHandle);
+ }
+ if (OutputHandle != INVALID_HANDLE_VALUE) {
+ CloseHandle (OutputHandle);
+ }
- return ErrorSuccess;
+ return Status;
}
void
@@ -630,7 +640,8 @@ GetPathInfo (
if (f == NULL) {
fprintf (stderr, "error E2003: File was not provided!\n");
return ErrorPath;
- }
+ }
+ fclose (f);
}
PathInfo->Type = PathFile;
strcpy(PathInfo->PhysicalPath, PathInfo->Path);