From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 272F22194EB61 for ; Thu, 13 Apr 2017 00:36:49 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Apr 2017 00:36:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,194,1488873600"; d="scan'208";a="86912950" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga005.jf.intel.com with ESMTP; 13 Apr 2017 00:36:48 -0700 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 13 Apr 2017 00:36:48 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 13 Apr 2017 00:36:47 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.117]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.217]) with mapi id 14.03.0319.002; Thu, 13 Apr 2017 15:36:46 +0800 From: "Wu, Jiaxin" To: "Zhang, Chao B" , "edk2-devel@lists.01.org" CC: "Ye, Ting" , "Fu, Siyuan" Thread-Topic: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource Thread-Index: AQHSsbNBNqDi5eqtAkOnng0heRLYbqHCBtoAgADm8GA= Date: Thu, 13 Apr 2017 07:36:45 +0000 Message-ID: <895558F6EA4E3B41AC93A00D163B7274162C0268@SHSMSX103.ccr.corp.intel.com> References: <1491798644-10212-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGUzYWM0YWYtNTI1ZC00YzBmLWFkMDktMWFkOTlhYzFjOWI0IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IjE2dTQ1cXdtaWZWUDd2R0toOUVEbmJ5d3FsWldQbnVGS0hPZzJPYnoyQ289In0= x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action 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 07:36:49 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks, chao, I will refine the patch as your comments. > -----Original Message----- > From: Zhang, Chao B > Sent: Thursday, April 13, 2017 9:49 AM > To: Wu, Jiaxin ; edk2-devel@lists.01.org > Cc: Ye, Ting ; Fu, Siyuan > Subject: RE: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file > related resource >=20 > Jiaxin: > I would like to recommend a new function to close the file handle in p= rivate > datastructure. The closing logic is now scattering around. >=20 > -----Original Message----- > From: Wu, Jiaxin > Sent: Monday, April 10, 2017 12:31 PM > To: edk2-devel@lists.01.org > Cc: Zhang, Chao B ; Ye, Ting ; > Fu, Siyuan ; Wu, Jiaxin > Subject: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file > related resource >=20 > TlsAuthConfigDxe open file by FileExplorerLib. It need to close file hand= ler > 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. >=20 > 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(-) >=20 > 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 ( > } >=20 > HiiGetBrowserData (&gTlsAuthConfigGuid, mTlsAuthConfigStorageName, > BufferSize, (UINT8 *) IfrNvData); >=20 > if ((Action !=3D EFI_BROWSER_ACTION_CHANGED) && > - (Action !=3D EFI_BROWSER_ACTION_CHANGING)) { > + (Action !=3D EFI_BROWSER_ACTION_CHANGING) && > + (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 > + // free the related resource first. > + // > + 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; > + } > + } > + > ChooseFile( NULL, NULL, UpdateCAFromFile, &File); > break; >=20 > case KEY_TLS_AUTH_CONFIG_VALUE_SAVE_AND_EXIT: > Status =3D EnrollCertDatabase (Private, > EFI_TLS_CA_CERTIFICATE_VARIABLE); > if (EFI_ERROR (Status)) { > + // > + // Close File and free the related resource. > + // > + 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; > + } > + } > + > 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. > + // > 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. > + // > + 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