MdeModulePkg:Fix the potential memory leak issue in Display Engine

The MenuOption insert to gMenuOption allocate memory every time,but not free.
Now add the code to free it.And for Date/Time,it will create 3 menus,but previously
the Description point to the same address,so when free the Description,it will cause
issue,now reset the Description pointer.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19647 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Dandan Bi
2016-01-15 09:50:40 +00:00
committed by dandanbi
parent 623538ff98
commit 0196c24a94

View File

@ -1,7 +1,7 @@
/** @file /** @file
Entry and initialization module for the browser. Entry and initialization module for the browser.
Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR> Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -604,7 +604,6 @@ UiAddMenuOption (
UI_MENU_OPTION *MenuOption; UI_MENU_OPTION *MenuOption;
UINTN Index; UINTN Index;
UINTN Count; UINTN Count;
CHAR16 *String;
UINT16 NumberOfLines; UINT16 NumberOfLines;
UINT16 GlyphWidth; UINT16 GlyphWidth;
UINT16 Width; UINT16 Width;
@ -621,9 +620,6 @@ UiAddMenuOption (
PromptId = GetPrompt (Statement->OpCode); PromptId = GetPrompt (Statement->OpCode);
ASSERT (PromptId != 0); ASSERT (PromptId != 0);
String = GetToken (PromptId, gFormData->HiiHandle);
ASSERT (String != NULL);
if (Statement->OpCode->OpCode == EFI_IFR_DATE_OP || Statement->OpCode->OpCode == EFI_IFR_TIME_OP) { if (Statement->OpCode->OpCode == EFI_IFR_DATE_OP || Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {
Count = 3; Count = 3;
} }
@ -633,7 +629,7 @@ UiAddMenuOption (
ASSERT (MenuOption); ASSERT (MenuOption);
MenuOption->Signature = UI_MENU_OPTION_SIGNATURE; MenuOption->Signature = UI_MENU_OPTION_SIGNATURE;
MenuOption->Description = String; MenuOption->Description = GetToken (PromptId, gFormData->HiiHandle);
MenuOption->Handle = gFormData->HiiHandle; MenuOption->Handle = gFormData->HiiHandle;
MenuOption->ThisTag = Statement; MenuOption->ThisTag = Statement;
MenuOption->NestInStatement = NestIn; MenuOption->NestInStatement = NestIn;
@ -697,11 +693,11 @@ UiAddMenuOption (
(Statement->OpCode->OpCode != EFI_IFR_DATE_OP) && (Statement->OpCode->OpCode != EFI_IFR_DATE_OP) &&
(Statement->OpCode->OpCode != EFI_IFR_TIME_OP)) { (Statement->OpCode->OpCode != EFI_IFR_TIME_OP)) {
Width = GetWidth (MenuOption, NULL); Width = GetWidth (MenuOption, NULL);
for (; GetLineByWidth (String, Width, &GlyphWidth,&ArrayEntry, &OutputString) != 0x0000;) { for (; GetLineByWidth (MenuOption->Description, Width, &GlyphWidth,&ArrayEntry, &OutputString) != 0x0000;) {
// //
// If there is more string to process print on the next row and increment the Skip value // If there is more string to process print on the next row and increment the Skip value
// //
if (StrLen (&String[ArrayEntry]) != 0) { if (StrLen (&MenuOption->Description[ArrayEntry]) != 0) {
NumberOfLines++; NumberOfLines++;
} }
FreePool (OutputString); FreePool (OutputString);
@ -3729,6 +3725,35 @@ UiDisplayMenu (
} }
} }
/**
Free the UI Menu Option structure data.
@param MenuOptionList Point to the menu option list which need to be free.
**/
VOID
FreeMenuOptionData(
LIST_ENTRY *MenuOptionList
)
{
LIST_ENTRY *Link;
UI_MENU_OPTION *Option;
//
// Free menu option list
//
while (!IsListEmpty (MenuOptionList)) {
Link = GetFirstNode (MenuOptionList);
Option = MENU_OPTION_FROM_LINK (Link);
if (Option->Description != NULL){
FreePool(Option->Description);
}
RemoveEntryList (&Option->Link);
FreePool (Option);
}
}
/** /**
Base on the browser status info to show an pop up message. Base on the browser status info to show an pop up message.
@ -4001,6 +4026,11 @@ FormDisplay (
CopyGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid); CopyGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid);
gOldFormEntry.FormId = FormData->FormId; gOldFormEntry.FormId = FormData->FormId;
//
//Free the Ui menu option list.
//
FreeMenuOptionData(&gMenuOption);
return Status; return Status;
} }