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.
Cc: Liming Gao <[email protected]> Cc: Eric Dong <[email protected]> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi <[email protected]> --- .../Universal/DisplayEngineDxe/FormDisplay.c | 46 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c index a391442..37cfcc5 100644 --- a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c +++ b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c @@ -1,9 +1,9 @@ /** @file 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> 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 http://opensource.org/licenses/bsd-license.php @@ -602,11 +602,10 @@ UiAddMenuOption ( ) { UI_MENU_OPTION *MenuOption; UINTN Index; UINTN Count; - CHAR16 *String; UINT16 NumberOfLines; UINT16 GlyphWidth; UINT16 Width; UINTN ArrayEntry; CHAR16 *OutputString; @@ -619,23 +618,20 @@ UiAddMenuOption ( MenuOption = NULL; PromptId = GetPrompt (Statement->OpCode); 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) { Count = 3; } for (Index = 0; Index < Count; Index++) { MenuOption = AllocateZeroPool (sizeof (UI_MENU_OPTION)); ASSERT (MenuOption); MenuOption->Signature = UI_MENU_OPTION_SIGNATURE; - MenuOption->Description = String; + MenuOption->Description = GetToken (PromptId, gFormData->HiiHandle); MenuOption->Handle = gFormData->HiiHandle; MenuOption->ThisTag = Statement; MenuOption->NestInStatement = NestIn; MenuOption->EntryNumber = *MenuItemCount; @@ -695,15 +691,15 @@ UiAddMenuOption ( if (Index == 0 && (Statement->OpCode->OpCode != EFI_IFR_DATE_OP) && (Statement->OpCode->OpCode != EFI_IFR_TIME_OP)) { 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 (StrLen (&String[ArrayEntry]) != 0) { + if (StrLen (&MenuOption->Description[ArrayEntry]) != 0) { NumberOfLines++; } FreePool (OutputString); } } else { @@ -3728,10 +3724,39 @@ 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. **/ VOID @@ -3999,10 +4024,15 @@ FormDisplay ( mIsFirstForm = FALSE; gOldFormEntry.HiiHandle = FormData->HiiHandle; CopyGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid); gOldFormEntry.FormId = FormData->FormId; + // + //Free the Ui menu option list. + // + FreeMenuOptionData(&gMenuOption); + return Status; } /** Clear Screen to the initial state. -- 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

