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.zh...@intel.com> Cc: Ye Ting <ting...@intel.com> Cc: Fu Siyuan <siyuan...@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin <jiaxin...@intel.com> --- NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c | 43 ++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c index 81f7e7d..23442fe 100644 --- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c +++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c @@ -1559,11 +1559,12 @@ TlsAuthConfigAccessCallback ( } HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, BufferSize, (UINT8 *) IfrNvData); if ((Action != EFI_BROWSER_ACTION_CHANGED) && - (Action != EFI_BROWSER_ACTION_CHANGING)) { + (Action != EFI_BROWSER_ACTION_CHANGING) && + (Action != EFI_BROWSER_ACTION_FORM_CLOSE)) { Status = EFI_UNSUPPORTED; goto EXIT; } if (Action == EFI_BROWSER_ACTION_CHANGING) { @@ -1590,26 +1591,54 @@ TlsAuthConfigAccessCallback ( // Refresh selected file. // CleanUpPage (LabelId, Private); break; case KEY_TLS_AUTH_CONFIG_ENROLL_CERT_FROM_FILE: + // + // If the file is already opened, then close and + // free the related resource first. + // + if (Private->FileContext->FHandle != NULL) { + CloseFile (Private->FileContext->FHandle); + Private->FileContext->FHandle = NULL; + if (Private->FileContext->FileName!= NULL){ + FreePool(Private->FileContext->FileName); + Private->FileContext->FileName = NULL; + } + } + ChooseFile( NULL, NULL, UpdateCAFromFile, &File); break; case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT: Status = EnrollCertDatabase (Private, EFI_TLS_CA_CERTIFICATE_VARIABLE); if (EFI_ERROR (Status)) { + // + // Close File and free the related resource. + // + if (Private->FileContext->FHandle != NULL) { + CloseFile (Private->FileContext->FHandle); + Private->FileContext->FHandle = NULL; + if (Private->FileContext->FileName!= NULL){ + FreePool(Private->FileContext->FileName); + Private->FileContext->FileName = NULL; + } + } + CreatePopUp ( EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"ERROR: Enroll Cert Failure!", NULL ); } break; case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT: + // + // Close File and free the related resource. + // if (Private->FileContext->FHandle != NULL) { CloseFile (Private->FileContext->FHandle); Private->FileContext->FHandle = NULL; if (Private->FileContext->FileName!= NULL){ FreePool(Private->FileContext->FileName); @@ -1665,10 +1694,22 @@ TlsAuthConfigAccessCallback ( *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; break; default: break; } + } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) { + // + // Close File and free the related resource. + // + if (Private->FileContext->FHandle != NULL) { + CloseFile (Private->FileContext->FHandle); + Private->FileContext->FHandle = NULL; + if (Private->FileContext->FileName!= NULL){ + FreePool(Private->FileContext->FileName); + Private->FileContext->FileName = NULL; + } + } } EXIT: if (!EFI_ERROR (Status)) { -- 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel