mirror of https://github.com/acidanthera/audk.git
BaseTools/Split: Fix potential memory and resource leak
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:
parent
399caf2d14
commit
b14f278de4
|
@ -223,14 +223,15 @@ Returns:
|
||||||
--*/
|
--*/
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
INTN ReturnStatus = STATUS_SUCCESS;
|
||||||
FILE *In;
|
FILE *In;
|
||||||
CHAR8 *InputFileName = NULL;
|
CHAR8 *InputFileName = NULL;
|
||||||
CHAR8 *OutputDir = NULL;
|
CHAR8 *OutputDir = NULL;
|
||||||
CHAR8 *OutFileName1 = NULL;
|
CHAR8 *OutFileName1 = NULL;
|
||||||
CHAR8 *OutFileName2 = NULL;
|
CHAR8 *OutFileName2 = NULL;
|
||||||
UINT64 SplitValue = (UINT64) -1;
|
UINT64 SplitValue = (UINT64) -1;
|
||||||
FILE *Out1;
|
FILE *Out1 = NULL;
|
||||||
FILE *Out2;
|
FILE *Out2 = NULL;
|
||||||
CHAR8 *OutName1 = NULL;
|
CHAR8 *OutName1 = NULL;
|
||||||
CHAR8 *OutName2 = NULL;
|
CHAR8 *OutName2 = NULL;
|
||||||
CHAR8 *CurrentDir = NULL;
|
CHAR8 *CurrentDir = NULL;
|
||||||
|
@ -366,7 +367,8 @@ Returns:
|
||||||
OutName1 = (CHAR8*)malloc(strlen(InputFileName) + 16);
|
OutName1 = (CHAR8*)malloc(strlen(InputFileName) + 16);
|
||||||
if (OutName1 == NULL) {
|
if (OutName1 == NULL) {
|
||||||
Warning (NULL, 0, 0, NULL, "Memory Allocation Fail.");
|
Warning (NULL, 0, 0, NULL, "Memory Allocation Fail.");
|
||||||
return STATUS_ERROR;
|
ReturnStatus = STATUS_ERROR;
|
||||||
|
goto Finish;
|
||||||
}
|
}
|
||||||
strcpy (OutName1, InputFileName);
|
strcpy (OutName1, InputFileName);
|
||||||
strcat (OutName1, "1");
|
strcat (OutName1, "1");
|
||||||
|
@ -377,7 +379,8 @@ Returns:
|
||||||
OutName2 = (CHAR8*)malloc(strlen(InputFileName) + 16);
|
OutName2 = (CHAR8*)malloc(strlen(InputFileName) + 16);
|
||||||
if (OutName2 == NULL) {
|
if (OutName2 == NULL) {
|
||||||
Warning (NULL, 0, 0, NULL, "Memory Allocation Fail.");
|
Warning (NULL, 0, 0, NULL, "Memory Allocation Fail.");
|
||||||
return STATUS_ERROR;
|
ReturnStatus = STATUS_ERROR;
|
||||||
|
goto Finish;
|
||||||
}
|
}
|
||||||
strcpy (OutName2, InputFileName);
|
strcpy (OutName2, InputFileName);
|
||||||
strcat (OutName2, "2");
|
strcat (OutName2, "2");
|
||||||
|
@ -389,20 +392,23 @@ Returns:
|
||||||
//OutputDirSpecified = TRUE;
|
//OutputDirSpecified = TRUE;
|
||||||
if (chdir(OutputDir) != 0) {
|
if (chdir(OutputDir) != 0) {
|
||||||
Warning (NULL, 0, 0, NULL, "Change dir to OutputDir Fail.");
|
Warning (NULL, 0, 0, NULL, "Change dir to OutputDir Fail.");
|
||||||
return STATUS_ERROR;
|
ReturnStatus = STATUS_ERROR;
|
||||||
|
goto Finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentDir = (CHAR8*)getcwd((CHAR8*)0, 0);
|
CurrentDir = (CHAR8*)getcwd((CHAR8*)0, 0);
|
||||||
if (EFI_ERROR(CreateDir(&OutFileName1))) {
|
if (EFI_ERROR(CreateDir(&OutFileName1))) {
|
||||||
Error (OutFileName1, 0, 5, "Create Dir for File1 Fail.", NULL);
|
Error (OutFileName1, 0, 5, "Create Dir for File1 Fail.", NULL);
|
||||||
return STATUS_ERROR;
|
ReturnStatus = STATUS_ERROR;
|
||||||
|
goto Finish;
|
||||||
}
|
}
|
||||||
chdir(CurrentDir);
|
chdir(CurrentDir);
|
||||||
|
|
||||||
if (EFI_ERROR(CreateDir(&OutFileName2))) {
|
if (EFI_ERROR(CreateDir(&OutFileName2))) {
|
||||||
Error (OutFileName2, 0, 5, "Create Dir for File2 Fail.", NULL);
|
Error (OutFileName2, 0, 5, "Create Dir for File2 Fail.", NULL);
|
||||||
return STATUS_ERROR;
|
ReturnStatus = STATUS_ERROR;
|
||||||
|
goto Finish;
|
||||||
}
|
}
|
||||||
chdir(CurrentDir);
|
chdir(CurrentDir);
|
||||||
free(CurrentDir);
|
free(CurrentDir);
|
||||||
|
@ -411,14 +417,16 @@ Returns:
|
||||||
if (Out1 == NULL) {
|
if (Out1 == NULL) {
|
||||||
// ("Unable to open file \"%s\"\n", OutFileName1);
|
// ("Unable to open file \"%s\"\n", OutFileName1);
|
||||||
Error (OutFileName1, 0, 1, "File open failure", NULL);
|
Error (OutFileName1, 0, 1, "File open failure", NULL);
|
||||||
return STATUS_ERROR;
|
ReturnStatus = STATUS_ERROR;
|
||||||
|
goto Finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
Out2 = fopen (LongFilePath (OutFileName2), "wb");
|
Out2 = fopen (LongFilePath (OutFileName2), "wb");
|
||||||
if (Out2 == NULL) {
|
if (Out2 == NULL) {
|
||||||
// ("Unable to open file \"%s\"\n", OutFileName2);
|
// ("Unable to open file \"%s\"\n", OutFileName2);
|
||||||
Error (OutFileName2, 0, 1, "File open failure", NULL);
|
Error (OutFileName2, 0, 1, "File open failure", NULL);
|
||||||
return STATUS_ERROR;
|
ReturnStatus = STATUS_ERROR;
|
||||||
|
goto Finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Index = 0; Index < SplitValue; Index++) {
|
for (Index = 0; Index < SplitValue; Index++) {
|
||||||
|
@ -439,15 +447,22 @@ Returns:
|
||||||
fputc (CharC, Out2);
|
fputc (CharC, Out2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Finish:
|
||||||
if (OutName1 != NULL) {
|
if (OutName1 != NULL) {
|
||||||
free(OutName1);
|
free(OutName1);
|
||||||
}
|
}
|
||||||
if (OutName2 != NULL) {
|
if (OutName2 != NULL) {
|
||||||
free(OutName2);
|
free(OutName2);
|
||||||
}
|
}
|
||||||
fclose (In);
|
if (In != NULL) {
|
||||||
fclose (Out1);
|
fclose (In);
|
||||||
fclose (Out2);
|
}
|
||||||
|
if (Out1 != NULL) {
|
||||||
|
fclose (Out1);
|
||||||
|
}
|
||||||
|
if (Out2 != NULL) {
|
||||||
|
fclose (Out2);
|
||||||
|
}
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return ReturnStatus;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue