From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 42CB721A0480E for ; Sun, 9 Apr 2017 21:30:54 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 09 Apr 2017 21:30:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,180,1488873600"; d="scan'208";a="86771466" Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.90]) by fmsmga005.fm.intel.com with ESMTP; 09 Apr 2017 21:30:52 -0700 From: Jiaxin Wu To: edk2-devel@lists.01.org Cc: Zhang Chao B , Ye Ting , Fu Siyuan , Wu Jiaxin Date: Mon, 10 Apr 2017 12:30:44 +0800 Message-Id: <1491798644-10212-1-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Apr 2017 04:30:54 -0000 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 Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- 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