]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/FileExplorerLib/FileExplorer.c
MdeModulePkg: FileExplorerLib: Add check when to call FreePool function
[mirror_edk2.git] / MdeModulePkg / Library / FileExplorerLib / FileExplorer.c
index bcf3ec97f6d05828df8c33ca225f4d90a39b0847..98c81dbef9e5b46e7f7519b2a819e0b434cfebf6 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
@@ -1442,7 +1446,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 +1495,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