public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wu, Jiaxin" <jiaxin.wu@intel.com>
To: "Zhang, Chao B" <chao.b.zhang@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Ye, Ting" <ting.ye@intel.com>, "Fu, Siyuan" <siyuan.fu@intel.com>
Subject: Re: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource
Date: Thu, 13 Apr 2017 07:36:45 +0000	[thread overview]
Message-ID: <895558F6EA4E3B41AC93A00D163B7274162C0268@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <FF72C7E4248F3C4E9BDF19D4918E90F24953837D@shsmsx102.ccr.corp.intel.com>

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 <jiaxin.wu@intel.com>; edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>
> Subject: RE: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file
> related resource
> 
> Jiaxin:
>    I would like to recommend a new function to close the file handle in private
> datastructure. The closing logic is now scattering around.
> 
> -----Original Message-----
> From: Wu, Jiaxin
> Sent: Monday, April 10, 2017 12:31 PM
> To: edk2-devel@lists.01.org
> Cc: Zhang, Chao B <chao.b.zhang@intel.com>; Ye, Ting <ting.ye@intel.com>;
> Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file
> related resource
> 
> 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>
> ---
>  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



      reply	other threads:[~2017-04-13  7:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-10  4:30 [Patch] NetworkPkg/TlsAuthConfigDxe: Close and free the file related resource Jiaxin Wu
2017-04-13  1:49 ` Zhang, Chao B
2017-04-13  7:36   ` Wu, Jiaxin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=895558F6EA4E3B41AC93A00D163B7274162C0268@SHSMSX103.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox