]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/FileExplorerLib/FileExplorer.c
MdeModulePkg: Add ASSERT to make sure pointers are not NULL
[mirror_edk2.git] / MdeModulePkg / Library / FileExplorerLib / FileExplorer.c
index bcf3ec97f6d05828df8c33ca225f4d90a39b0847..9f75d6ede544080eec8fc8a8ad602ab6d56b8519 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 File explorer related functions.\r
 \r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
@@ -302,7 +302,9 @@ LibDestroyMenuEntry (
   FileContext = (FILE_CONTEXT *) MenuEntry->VariableContext;\r
 \r
   if (!FileContext->IsRoot) {\r
-    FreePool (FileContext->DevicePath);\r
+    if (FileContext->DevicePath != NULL) {\r
+      FreePool (FileContext->DevicePath);\r
+    }\r
   } else {\r
     if (FileContext->FileHandle != NULL) {\r
       FileContext->FileHandle->Close (FileContext->FileHandle);\r
@@ -315,7 +317,9 @@ LibDestroyMenuEntry (
 \r
   FreePool (FileContext);\r
 \r
-  FreePool (MenuEntry->DisplayString);\r
+  if (MenuEntry->DisplayString != NULL) {\r
+    FreePool (MenuEntry->DisplayString);\r
+  }\r
   if (MenuEntry->HelpString != NULL) {\r
     FreePool (MenuEntry->HelpString);\r
   }\r
@@ -580,6 +584,7 @@ LibIsSupportedFileType (
   }\r
 \r
   TmpStr = AllocateCopyPool (StrSize (InputFileType), InputFileType);\r
+  ASSERT(TmpStr != NULL);\r
   LibToLowerString(TmpStr);\r
 \r
   IsSupported = (StrStr (gFileExplorerPrivate.FileType, TmpStr) == NULL ? FALSE : TRUE);\r
@@ -1357,6 +1362,7 @@ ChooseFile (
   gFileExplorerPrivate.ChooseHandler = ChooseHandler;\r
   if (FileType != NULL) {\r
     gFileExplorerPrivate.FileType = AllocateCopyPool (StrSize (FileType), FileType);\r
+    ASSERT(gFileExplorerPrivate.FileType != NULL);\r
     LibToLowerString(gFileExplorerPrivate.FileType);\r
   } else {\r
     gFileExplorerPrivate.FileType = NULL;\r
@@ -1442,7 +1448,12 @@ FileExplorerLibConstructor (
                   &gFileExplorerPrivate.FeConfigAccess,\r
                   NULL\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   //\r
   // Post our File Explorer VFR binary to the HII database.\r
@@ -1486,17 +1497,19 @@ FileExplorerLibDestructor (
 \r
   ASSERT (gHiiVendorDevicePath != NULL);\r
 \r
-  Status = gBS->UninstallMultipleProtocolInterfaces (\r
-                  gFileExplorerPrivate.FeDriverHandle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  gHiiVendorDevicePath,\r
-                  &gEfiHiiConfigAccessProtocolGuid,\r
-                  &gFileExplorerPrivate.FeConfigAccess,\r
-                  NULL\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-  \r
-  HiiRemovePackages (gFileExplorerPrivate.FeHiiHandle);\r
+  if (gFileExplorerPrivate.FeDriverHandle != NULL) {\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                    gFileExplorerPrivate.FeDriverHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    gHiiVendorDevicePath,\r
+                    &gEfiHiiConfigAccessProtocolGuid,\r
+                    &gFileExplorerPrivate.FeConfigAccess,\r
+                    NULL\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    HiiRemovePackages (gFileExplorerPrivate.FeHiiHandle);\r
+  }\r
 \r
   FreePool (gHiiVendorDevicePath);\r
 \r