diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c index 87d4fa88b9..9129b5067e 100644 --- a/BaseTools/Source/C/GenSec/GenSec.c +++ b/BaseTools/Source/C/GenSec/GenSec.c @@ -897,16 +897,22 @@ Returns: return Status; } - if (FileBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - if (InputLength == 0) { - free (FileBuffer); + if (FileBuffer != NULL) { + free (FileBuffer); + } Error (NULL, 0, 2000, "Invalid parameter", "the size of input file %s can't be zero", InputFileName); return EFI_NOT_FOUND; } + // + // InputLength != 0, but FileBuffer == NULL means out of resources. + // + if (FileBuffer == NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + return EFI_OUT_OF_RESOURCES; + } + // // Now data is in FileBuffer + Offset //