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...@intel.com>; edk2-devel@lists.01.org > Cc: Ye, Ting <ting...@intel.com>; Fu, Siyuan <siyuan...@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.zh...@intel.com>; Ye, Ting <ting...@intel.com>; > Fu, Siyuan <siyuan...@intel.com>; Wu, Jiaxin <jiaxin...@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.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