From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 503B121A18AAB for ; Wed, 12 Apr 2017 18:49:30 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Apr 2017 18:49:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,192,1488873600"; d="scan'208";a="845183600" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 12 Apr 2017 18:49:29 -0700 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 12 Apr 2017 18:49:29 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 12 Apr 2017 18:49:29 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.246]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.193]) with mapi id 14.03.0319.002; Thu, 13 Apr 2017 09:49:27 +0800 From: "Zhang, Chao B" To: "Wu, Jiaxin" , "edk2-devel@lists.01.org" CC: "Ye, Ting" , "Fu, Siyuan" Thread-Topic: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource Thread-Index: AQHSsbNBsy2O9VNLckSBevrSKjfEyaHCjFKw Date: Thu, 13 Apr 2017 01:49:26 +0000 Message-ID: References: <1491798644-10212-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: <1491798644-10212-1-git-send-email-jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: Thu, 13 Apr 2017 01:49:30 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Jiaxin: I would like to recommend a new function to close the file handle in pri= vate datastructure. The closing logic is now scattering around. -----Original Message----- From: Wu, Jiaxin=20 Sent: Monday, April 10, 2017 12:31 PM To: edk2-devel@lists.01.org Cc: Zhang, Chao B ; Ye, Ting ; F= u, Siyuan ; Wu, Jiaxin Subject: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file relat= ed resource TlsAuthConfigDxe open file by FileExplorerLib. It need to close file handle= r 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/T= lsAuthConfigDxe/TlsAuthConfigImpl.c index 81f7e7d..23442fe 100644 --- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c +++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c @@ -1559,11 +1559,12 @@ TlsAuthConfigAccessCallback ( } =20 HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, Buffe= rSize, (UINT8 *) IfrNvData); =20 if ((Action !=3D EFI_BROWSER_ACTION_CHANGED) && - (Action !=3D EFI_BROWSER_ACTION_CHANGING)) { + (Action !=3D EFI_BROWSER_ACTION_CHANGING) &&=20 + (Action !=3D EFI_BROWSER_ACTION_FORM_CLOSE)) { Status =3D EFI_UNSUPPORTED; goto EXIT; } =20 if (Action =3D=3D 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=20 + // free the related resource first.=20 + // + if (Private->FileContext->FHandle !=3D NULL) { + CloseFile (Private->FileContext->FHandle); + Private->FileContext->FHandle =3D NULL; + if (Private->FileContext->FileName!=3D NULL){ + FreePool(Private->FileContext->FileName); + Private->FileContext->FileName =3D NULL; + } + } + =20 ChooseFile( NULL, NULL, UpdateCAFromFile, &File); break; =20 case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT: Status =3D EnrollCertDatabase (Private, EFI_TLS_CA_CERTIFICATE_VARIA= BLE); if (EFI_ERROR (Status)) { + // + // Close File and free the related resource.=20 + // + if (Private->FileContext->FHandle !=3D NULL) { + CloseFile (Private->FileContext->FHandle); + Private->FileContext->FHandle =3D NULL; + if (Private->FileContext->FileName!=3D NULL){ + FreePool(Private->FileContext->FileName); + Private->FileContext->FileName =3D NULL; + } + } + =20 CreatePopUp ( EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"ERROR: Enroll Cert Failure!", NULL ); } break; =20 case KEY_TLS_AUTH_CONFIG_VALUE_NO_SAVE_AND_EXIT: + // + // Close File and free the related resource.=20 + // if (Private->FileContext->FHandle !=3D NULL) { CloseFile (Private->FileContext->FHandle); Private->FileContext->FHandle =3D NULL; if (Private->FileContext->FileName!=3D NULL){ FreePool(Private->FileContext->FileName); @@ -1665,10 +1694,22 @@ TlsAuthConfigAccessCallback ( *ActionRequest =3D EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; break; default: break; } + } else if (Action =3D=3D EFI_BROWSER_ACTION_FORM_CLOSE) { + // + // Close File and free the related resource.=20 + // + if (Private->FileContext->FHandle !=3D NULL) { + CloseFile (Private->FileContext->FHandle); + Private->FileContext->FHandle =3D NULL; + if (Private->FileContext->FileName!=3D NULL){ + FreePool(Private->FileContext->FileName); + Private->FileContext->FileName =3D NULL; + } + } } =20 EXIT: =20 if (!EFI_ERROR (Status)) { -- 1.9.5.msysgit.1