]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
update error handling to use less ASSERT.
[mirror_edk2.git] / ShellPkg / Library / UefiShellCommandLib / UefiShellCommandLib.c
index 4aec5d44ca0583b261cf606bfeca8bdbe6bd407f..2dd39ef3cf453b091903b3c72d44e0e501c58625 100644 (file)
@@ -1171,7 +1171,8 @@ ConvertShellHandleToEfiFileProtocol(
   @param[in] Handle     The pointer to EFI_FILE_PROTOCOL to convert.\r
   @param[in] Path       The path to the file for verification.\r
 \r
-  @return a SHELL_FILE_HANDLE representing the same file.\r
+  @return               A SHELL_FILE_HANDLE representing the same file.\r
+  @retval NULL          There was not enough memory.\r
 **/\r
 SHELL_FILE_HANDLE\r
 EFIAPI\r
@@ -1185,11 +1186,18 @@ ConvertEfiFileProtocolToShellHandle(
 \r
   if (Path != NULL) {\r
     Buffer              = AllocateZeroPool(sizeof(SHELL_COMMAND_FILE_HANDLE));\r
-    ASSERT(Buffer  != NULL);\r
+    if (Buffer == NULL) {\r
+      return (NULL);\r
+    }\r
     NewNode             = AllocatePool(sizeof(BUFFER_LIST));\r
-    ASSERT(NewNode != NULL);\r
+    if (NewNode == NULL) {\r
+      return (NULL);\r
+    }\r
     Buffer->FileHandle  = (EFI_FILE_PROTOCOL*)Handle;\r
     Buffer->Path        = StrnCatGrow(&Buffer->Path, NULL, Path, 0);\r
+    if (Buffer->Path == NULL) {\r
+      return (NULL);\r
+    }\r
     NewNode->Buffer     = Buffer;\r
 \r
     InsertHeadList(&mFileHandleList.Link, &NewNode->Link);\r
@@ -1244,8 +1252,10 @@ ShellFileHandleRemove(
     ;  Node = (BUFFER_LIST*)GetNextNode(&mFileHandleList.Link, &Node->Link)\r
    ){\r
     if ((Node->Buffer) && (((SHELL_COMMAND_FILE_HANDLE *)Node->Buffer)->FileHandle == Handle)){\r
-      SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE *)Node->Buffer)->Path);\r
       RemoveEntryList(&Node->Link);\r
+      SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE *)Node->Buffer)->Path);\r
+      SHELL_FREE_NON_NULL(Node->Buffer);\r
+      SHELL_FREE_NON_NULL(Node);\r
       return (TRUE);\r
     }\r
   }\r