[edk2] [PATCH 2/2] MdePkg DxeHstiLib: Fix memory leak issue

Star Zeng posted 2 patches 7 years, 5 months ago
[edk2] [PATCH 2/2] MdePkg DxeHstiLib: Fix memory leak issue
Posted by Star Zeng 7 years, 5 months ago
The Hsti returned from InternalHstiFindAip() and temporally
allocated NewHsti need to be freed after used.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdePkg/Library/DxeHstiLib/HstiDxe.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/DxeHstiLib/HstiDxe.c b/MdePkg/Library/DxeHstiLib/HstiDxe.c
index c032a98647bf..58510766bb43 100644
--- a/MdePkg/Library/DxeHstiLib/HstiDxe.c
+++ b/MdePkg/Library/DxeHstiLib/HstiDxe.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
   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
@@ -206,7 +206,7 @@ InternalHstiIsValidTable (
     }
   }
   if (Index == sizeof(Hsti->ImplementationID)/sizeof(Hsti->ImplementationID[0])) {
-    DEBUG ((EFI_D_ERROR, "ImplementationID is no NUL CHAR\n"));
+    DEBUG ((EFI_D_ERROR, "ImplementationID has no NUL CHAR\n"));
     return FALSE;
   }
 
@@ -416,6 +416,7 @@ InternalHstiRecordFeaturesVerified (
                   Hsti,
                   HstiSize
                   );
+  FreePool (Hsti);
   return Status;
 }
 
@@ -545,6 +546,8 @@ InternalHstiRecordErrorString (
                   NewHsti,
                   NewHstiSize
                   );
+  FreePool (Hsti);
+  FreePool (NewHsti);
   return Status;
 }
 
-- 
2.7.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 2/2] MdePkg DxeHstiLib: Fix memory leak issue
Posted by Yao, Jiewen 7 years, 5 months ago
Reviewed-by: Jiewen.yao@intel.com

> -----Original Message-----
> From: Zeng, Star
> Sent: Friday, July 14, 2017 4:54 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>
> Subject: [PATCH 2/2] MdePkg DxeHstiLib: Fix memory leak issue
> 
> The Hsti returned from InternalHstiFindAip() and temporally
> allocated NewHsti need to be freed after used.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Star Zeng <star.zeng@intel.com>
> ---
>  MdePkg/Library/DxeHstiLib/HstiDxe.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/MdePkg/Library/DxeHstiLib/HstiDxe.c
> b/MdePkg/Library/DxeHstiLib/HstiDxe.c
> index c032a98647bf..58510766bb43 100644
> --- a/MdePkg/Library/DxeHstiLib/HstiDxe.c
> +++ b/MdePkg/Library/DxeHstiLib/HstiDxe.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
>    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
> @@ -206,7 +206,7 @@ InternalHstiIsValidTable (
>      }
>    }
>    if (Index ==
> sizeof(Hsti->ImplementationID)/sizeof(Hsti->ImplementationID[0])) {
> -    DEBUG ((EFI_D_ERROR, "ImplementationID is no NUL CHAR\n"));
> +    DEBUG ((EFI_D_ERROR, "ImplementationID has no NUL CHAR\n"));
>      return FALSE;
>    }
> 
> @@ -416,6 +416,7 @@ InternalHstiRecordFeaturesVerified (
>                    Hsti,
>                    HstiSize
>                    );
> +  FreePool (Hsti);
>    return Status;
>  }
> 
> @@ -545,6 +546,8 @@ InternalHstiRecordErrorString (
>                    NewHsti,
>                    NewHstiSize
>                    );
> +  FreePool (Hsti);
> +  FreePool (NewHsti);
>    return Status;
>  }
> 
> --
> 2.7.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel