From 251779fca719bf9ea00505ee7629c08b452c150d Mon Sep 17 00:00:00 2001 From: Jiewen Yao Date: Mon, 27 Mar 2017 23:01:02 +0800 Subject: [PATCH] MdeModulePkg/SmmCore: Fix memory leak on Profile unregistered. Issue reported at bugzillar 445. Cc: Jeff Fan Cc: Feng Tian Cc: Star Zeng Cc: Bret Barkelew Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiewen Yao Reviewed-by: Jeff Fan --- MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c index 1e36039dd4..ad3b54ace4 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c +++ b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c @@ -1186,7 +1186,9 @@ SmiHandlerProfileRegisterHandler ( SmiEntry = SmmCoreFindHardwareSmiEntry (HandlerGuid, TRUE); if (SmiEntry == NULL) { - FreePool (SmiHandler->Context); + if (SmiHandler->Context != NULL) { + FreePool (SmiHandler->Context); + } FreePool (SmiHandler); return EFI_OUT_OF_RESOURCES; } @@ -1277,6 +1279,9 @@ SmiHandlerProfileUnregisterHandler ( SmiHandler = TargetSmiHandler; RemoveEntryList (&SmiHandler->Link); + if (SmiHandler->Context != NULL) { + FreePool (SmiHandler->Context); + } FreePool (SmiHandler); if (IsListEmpty (&SmiEntry->SmiHandlers)) { -- 2.39.2