\r
/**\r
Extract filename from device path. The returned buffer is allocated using AllocateCopyPool.\r
- The caller is responsible for freeing the allocated buffer using FreePool().\r
+ The caller is responsible for freeing the allocated buffer using FreePool(). If return NULL\r
+ means not enough memory resource.\r
\r
@param DevicePath Device path.\r
\r
- @return A new allocated string that represents the file name.\r
+ @retval NULL Not enough memory resourece for AllocateCopyPool.\r
+ @retval Other A new allocated string that represents the file name.\r
\r
**/\r
CHAR16 *\r
String = DevicePathToStr(DevicePath);\r
MatchString = String;\r
LastMatch = String;\r
+ FileName = NULL;\r
\r
while(MatchString != NULL){\r
LastMatch = MatchString + 1;\r
\r
Length = StrLen(LastMatch);\r
FileName = AllocateCopyPool ((Length + 1) * sizeof(CHAR16), LastMatch);\r
- *(FileName + Length) = 0;\r
+ if (FileName != NULL) {\r
+ *(FileName + Length) = 0;\r
+ }\r
\r
FreePool(String);\r
\r
CHAR16 *FileName;\r
EFI_STRING_ID StringToken;\r
\r
- if (FilePath != NULL){\r
+ FileName = NULL;\r
+\r
+ if (FilePath != NULL) {\r
FileName = ExtractFileNameFromDevicePath(FilePath);\r
- StringToken = HiiSetString (gSecureBootPrivateData->HiiHandle, 0, FileName, NULL);\r
- } else {\r
- FileName = HiiGetString (gSecureBootPrivateData->HiiHandle, STRING_TOKEN (STR_NULL), NULL);\r
- ASSERT (FileName != NULL);\r
- StringToken = HiiSetString (gSecureBootPrivateData->HiiHandle, 0, FileName, NULL);\r
}\r
+ if (FileName == NULL) {\r
+ //\r
+ // FileName = NULL has two case:\r
+ // 1. FilePath == NULL, not select file.\r
+ // 2. FilePath != NULL, but ExtractFileNameFromDevicePath return NULL not enough memory resource.\r
+ // In these two case, no need to update the form, and exit the caller function.\r
+ //\r
+ return TRUE;\r
+ }\r
+ StringToken = HiiSetString (gSecureBootPrivateData->HiiHandle, 0, FileName, NULL);\r
\r
gSecureBootPrivateData->FileContext->FileName = FileName;\r
\r