From 45ea8a0c4550e1bb357d9e1d7fe653cd79cacaf5 Mon Sep 17 00:00:00 2001 From: Jiaxin Wu Date: Mon, 31 Jul 2017 13:36:37 +0800 Subject: [PATCH] NetworkPkg/HttpDxe: Destroy the TLS instance when cleaning up the HTTP child During clean up the HTTP child, all resources used by it should be cleaned. But currently, TLS instance is not destroyed. This patch is to fix this issue. Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan --- NetworkPkg/HttpDxe/HttpImpl.c | 1 + NetworkPkg/HttpDxe/HttpProto.c | 7 +++++++ NetworkPkg/HttpDxe/HttpProto.h | 3 ++- NetworkPkg/HttpDxe/HttpsSupport.c | 14 +++++++------- NetworkPkg/HttpDxe/HttpsSupport.h | 4 +++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index c9ad59b168..8a9e57345a 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -380,6 +380,7 @@ EfiHttpRequest ( HttpInstance->TlsChildHandle = TlsCreateChild ( ImageHandle, + &(HttpInstance->TlsSb), &(HttpInstance->Tls), &(HttpInstance->TlsConfiguration) ); diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index 3fda294be3..ab00f3d6f2 100644 --- a/NetworkPkg/HttpDxe/HttpProto.c +++ b/NetworkPkg/HttpDxe/HttpProto.c @@ -864,6 +864,13 @@ HttpCleanProtocol ( NetMapClean (&HttpInstance->TxTokens); NetMapClean (&HttpInstance->RxTokens); + if (HttpInstance->TlsSb != NULL && HttpInstance->TlsChildHandle != NULL) { + // + // Destroy the TLS instance. + // + HttpInstance->TlsSb->DestroyChild (HttpInstance->TlsSb, HttpInstance->TlsChildHandle); + } + if (HttpInstance->Tcp4ChildHandle != NULL) { gBS->CloseProtocol ( HttpInstance->Tcp4ChildHandle, diff --git a/NetworkPkg/HttpDxe/HttpProto.h b/NetworkPkg/HttpDxe/HttpProto.h index 95fb4843ce..04d36aaca0 100644 --- a/NetworkPkg/HttpDxe/HttpProto.h +++ b/NetworkPkg/HttpDxe/HttpProto.h @@ -166,7 +166,8 @@ typedef struct _HTTP_PROTOCOL { // Https Support // BOOLEAN UseHttps; - + + EFI_SERVICE_BINDING_PROTOCOL *TlsSb; EFI_HANDLE TlsChildHandle; /// Tls ChildHandle TLS_CONFIG_DATA TlsConfigData; EFI_TLS_PROTOCOL *Tls; diff --git a/NetworkPkg/HttpDxe/HttpsSupport.c b/NetworkPkg/HttpDxe/HttpsSupport.c index e4d9a37bee..e6f4d5a6cc 100644 --- a/NetworkPkg/HttpDxe/HttpsSupport.c +++ b/NetworkPkg/HttpDxe/HttpsSupport.c @@ -140,6 +140,7 @@ IsHttpsUrl ( Creates a Tls child handle, open EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL. @param[in] ImageHandle The firmware allocated handle for the UEFI image. + @param[out] TlsSb Pointer to the TLS SERVICE_BINDING_PROTOCOL. @param[out] TlsProto Pointer to the EFI_TLS_PROTOCOL instance. @param[out] TlsConfiguration Pointer to the EFI_TLS_CONFIGURATION_PROTOCOL instance. @@ -150,15 +151,14 @@ EFI_HANDLE EFIAPI TlsCreateChild ( IN EFI_HANDLE ImageHandle, + OUT EFI_SERVICE_BINDING_PROTOCOL **TlsSb, OUT EFI_TLS_PROTOCOL **TlsProto, OUT EFI_TLS_CONFIGURATION_PROTOCOL **TlsConfiguration ) { EFI_STATUS Status; - EFI_SERVICE_BINDING_PROTOCOL *TlsSb; EFI_HANDLE TlsChildHandle; - TlsSb = NULL; TlsChildHandle = 0; // @@ -167,13 +167,13 @@ TlsCreateChild ( gBS->LocateProtocol ( &gEfiTlsServiceBindingProtocolGuid, NULL, - (VOID **) &TlsSb + (VOID **) TlsSb ); - if (TlsSb == NULL) { + if (*TlsSb == NULL) { return NULL; } - Status = TlsSb->CreateChild (TlsSb, &TlsChildHandle); + Status = (*TlsSb)->CreateChild (*TlsSb, &TlsChildHandle); if (EFI_ERROR (Status)) { return NULL; } @@ -187,7 +187,7 @@ TlsCreateChild ( EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { - TlsSb->DestroyChild (TlsSb, TlsChildHandle); + (*TlsSb)->DestroyChild (*TlsSb, TlsChildHandle); return NULL; } @@ -200,7 +200,7 @@ TlsCreateChild ( EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { - TlsSb->DestroyChild (TlsSb, TlsChildHandle); + (*TlsSb)->DestroyChild (*TlsSb, TlsChildHandle); return NULL; } diff --git a/NetworkPkg/HttpDxe/HttpsSupport.h b/NetworkPkg/HttpDxe/HttpsSupport.h index 68a6073ceb..f7a2d303e6 100644 --- a/NetworkPkg/HttpDxe/HttpsSupport.h +++ b/NetworkPkg/HttpDxe/HttpsSupport.h @@ -1,7 +1,7 @@ /** @file The header files of miscellaneous routines specific to Https for HttpDxe driver. -Copyright (c) 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -37,6 +37,7 @@ IsHttpsUrl ( Creates a Tls child handle, open EFI_TLS_PROTOCOL and EFI_TLS_CONFIGURATION_PROTOCOL. @param[in] ImageHandle The firmware allocated handle for the UEFI image. + @param[out] TlsSb Pointer to the TLS SERVICE_BINDING_PROTOCOL. @param[out] TlsProto Pointer to the EFI_TLS_PROTOCOL instance. @param[out] TlsConfiguration Pointer to the EFI_TLS_CONFIGURATION_PROTOCOL instance. @@ -47,6 +48,7 @@ EFI_HANDLE EFIAPI TlsCreateChild ( IN EFI_HANDLE ImageHandle, + OUT EFI_SERVICE_BINDING_PROTOCOL **TlsSb, OUT EFI_TLS_PROTOCOL **TlsProto, OUT EFI_TLS_CONFIGURATION_PROTOCOL **TlsConfiguration ); -- 2.39.2