mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
StandaloneMmPkg/Core: Fix memory leak in MmiHandlerRegister
In MmiHandlerRegister(), the MmiHandler structure is currently allocated before looking up the target MmiEntry. If the lookup fails, the function returns an error but the allocated MmiHandler is never freed, causing a memory leak. This patch moves the allocation of MmiHandler and its initialization to after the MmiEntry lookup and validation. This ensures that memory is only allocated when the operation can succeed, eliminating the need for a FreePool() on the error path and simplifying the error handling logic. Signed-off-by: Qihang Gao <gaoqihang@loongson.cn> Suggested-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
parent
f246d215ea
commit
8d2bbdfb14
1 changed files with 9 additions and 10 deletions
|
|
@ -367,15 +367,6 @@ MmiHandlerRegister (
|
|||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
MmiHandler = AllocateZeroPool (sizeof (MMI_HANDLER));
|
||||
if (MmiHandler == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
MmiHandler->Signature = MMI_HANDLER_SIGNATURE;
|
||||
MmiHandler->Handler = Handler;
|
||||
MmiHandler->ToRemove = FALSE;
|
||||
|
||||
if (HandlerType == NULL) {
|
||||
//
|
||||
// This is root MMI handler
|
||||
|
|
@ -394,7 +385,15 @@ MmiHandlerRegister (
|
|||
List = &MmiEntry->MmiHandlers;
|
||||
}
|
||||
|
||||
MmiHandler->MmiEntry = MmiEntry;
|
||||
MmiHandler = AllocateZeroPool (sizeof (MMI_HANDLER));
|
||||
if (MmiHandler == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
MmiHandler->Signature = MMI_HANDLER_SIGNATURE;
|
||||
MmiHandler->Handler = Handler;
|
||||
MmiHandler->ToRemove = FALSE;
|
||||
MmiHandler->MmiEntry = MmiEntry;
|
||||
InsertTailList (List, &MmiHandler->Link);
|
||||
|
||||
*DispatchHandle = (EFI_HANDLE)MmiHandler;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue