]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource
authorJiaxin Wu <jiaxin.wu@intel.com>
Mon, 10 Apr 2017 02:30:38 +0000 (10:30 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Fri, 21 Apr 2017 05:05:27 +0000 (13:05 +0800)
v2:
* Define one new internal function to clean the file content.

TlsAuthConfigDxe open file by FileExplorerLib. It need to close
file handler and free file related resource in some cases.
* User enrolls Cert by escape the Config page.
* The Cert is not X509 type.
* User chooses another file after he selected a file.

Cc: Zhang Chao B <chao.b.zhang@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Chao Zhang<chao.b.zhang@intel.com>
NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c

index 81f7e7d0f4f136c88f7d854b8ba79742c6bd549e..faefc72d0efa952a571703e74b8f9a948698b521 100644 (file)
@@ -296,7 +296,7 @@ ON_EXIT:
 /**\r
   Delete one entry from cert database.\r
 \r
-  @param[in]    PrivateData         Module's private data.\r
+  @param[in]    Private             Module's private data.\r
   @param[in]    VariableName        The variable name of the database.\r
   @param[in]    VendorGuid          A unique identifier for the vendor.\r
   @param[in]    LabelNumber         Label number to insert opcodes.\r
@@ -477,18 +477,23 @@ ON_EXIT:
 \r
 \r
 /**\r
-  Close an open file handle.\r
+  Clean the file related resource.\r
 \r
-  @param[in] FileHandle           The file handle to close.\r
+  @param[in]    Private             Module's private data.\r
 \r
 **/\r
 VOID\r
-CloseFile (\r
-  IN EFI_FILE_HANDLE   FileHandle\r
+CleanFileContext (\r
+  IN TLS_AUTH_CONFIG_PRIVATE_DATA     *Private\r
   )\r
 {\r
-  if (FileHandle != NULL) {\r
-    FileHandle->Close (FileHandle);\r
+  if (Private->FileContext->FHandle != NULL) {\r
+    Private->FileContext->FHandle->Close (Private->FileContext->FHandle);\r
+    Private->FileContext->FHandle = NULL;\r
+    if (Private->FileContext->FileName!= NULL){\r
+      FreePool(Private->FileContext->FileName);\r
+      Private->FileContext->FileName = NULL;\r
+    }\r
   }\r
 }\r
 \r
@@ -873,14 +878,7 @@ EnrollX509toVariable (
   }\r
 \r
 ON_EXIT:\r
-\r
-  CloseFile (Private->FileContext->FHandle);\r
-  if (Private->FileContext->FileName != NULL) {\r
-    FreePool(Private->FileContext->FileName);\r
-    Private->FileContext->FileName = NULL;\r
-  }\r
-\r
-  Private->FileContext->FHandle = NULL;\r
+  CleanFileContext (Private);\r
 \r
   if (Private->CertGuid != NULL) {\r
     FreePool (Private->CertGuid);\r
@@ -1561,7 +1559,8 @@ TlsAuthConfigAccessCallback (
   HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, BufferSize, (UINT8 *) IfrNvData);\r
 \r
   if ((Action != EFI_BROWSER_ACTION_CHANGED) &&\r
-      (Action != EFI_BROWSER_ACTION_CHANGING)) {\r
+      (Action != EFI_BROWSER_ACTION_CHANGING) && \r
+      (Action != EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
     Status = EFI_UNSUPPORTED;\r
     goto EXIT;\r
   }\r
@@ -1592,12 +1591,19 @@ TlsAuthConfigAccessCallback (
       CleanUpPage (LabelId, Private);\r
       break;\r
     case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE:\r
+      //\r
+      // If the file is already opened, clean the file related resource first. \r
+      //\r
+      CleanFileContext (Private);\r
+      \r
       ChooseFile( NULL, NULL, UpdateCAFromFile, &File);\r
       break;\r
 \r
     case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT:\r
       Status = EnrollCertDatabase (Private, EFI_TLS_CA_CERTIFICATE_VARIABLE);\r
       if (EFI_ERROR (Status)) {\r
+        CleanFileContext (Private);\r
+\r
         CreatePopUp (\r
           EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
           &Key,\r
@@ -1608,14 +1614,7 @@ TlsAuthConfigAccessCallback (
       break;\r
 \r
     case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT:\r
-      if (Private->FileContext->FHandle != NULL) {\r
-        CloseFile (Private->FileContext->FHandle);\r
-        Private->FileContext->FHandle = NULL;\r
-        if (Private->FileContext->FileName!= NULL){\r
-          FreePool(Private->FileContext->FileName);\r
-          Private->FileContext->FileName = NULL;\r
-        }\r
-      }\r
+      CleanFileContext (Private);\r
 \r
       if (Private->CertGuid!= NULL) {\r
         FreePool (Private->CertGuid);\r
@@ -1667,6 +1666,8 @@ TlsAuthConfigAccessCallback (
     default:\r
       break;\r
     }\r
+  } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {\r
+    CleanFileContext (Private);\r
   }\r
 \r
 EXIT:\r