MdeModulePkg/SmmCore: Fix memory leak on Profile unregistered.
authorJiewen Yao <jiewen.yao@intel.com>
Mon, 27 Mar 2017 15:01:02 +0000 (23:01 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Fri, 31 Mar 2017 00:22:53 +0000 (08:22 +0800)
Issue reported at bugzillar 445.

Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c

index 1e36039..ad3b54a 100644 (file)
@@ -1186,7 +1186,9 @@ SmiHandlerProfileRegisterHandler (
 \r
   SmiEntry = SmmCoreFindHardwareSmiEntry (HandlerGuid, TRUE);\r
   if (SmiEntry == NULL) {\r
-    FreePool (SmiHandler->Context);\r
+    if (SmiHandler->Context != NULL) {\r
+      FreePool (SmiHandler->Context);\r
+    }\r
     FreePool (SmiHandler);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -1277,6 +1279,9 @@ SmiHandlerProfileUnregisterHandler (
   SmiHandler = TargetSmiHandler;\r
 \r
   RemoveEntryList (&SmiHandler->Link);\r
+  if (SmiHandler->Context != NULL) {\r
+    FreePool (SmiHandler->Context);\r
+  }\r
   FreePool (SmiHandler);\r
 \r
   if (IsListEmpty (&SmiEntry->SmiHandlers)) {\r