mirror of https://github.com/acidanthera/audk.git
ShellPkg/App: Fix memory leak and save resources.
1) RunSplitCommand() allocates the initial SplitStdOut via CreateFileInterfaceMem(). Free SplitStdIn after the swap to fix the memory leak. 2) In RunSplitCommand(), SplitStdOut is checked for equality with StdIn. This cannot happen due to the if-check within the swap. Hence remove it. 3) UefiMain() doesn't free SplitList. Delete all list entries and reinitialize the list when in DEBUG. This does not include the CreateFileInterfaceMem()-allocated SplitStd mentioned in 1), so keep the ASSERT() until resolved. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com> Reviewed-by: Qiu Shumin <shumin.qiu@intel.com>
This commit is contained in:
parent
dc99315b87
commit
bd3fc8133b
|
@ -342,6 +342,7 @@ UefiMain (
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
EFI_HANDLE ConInHandle;
|
EFI_HANDLE ConInHandle;
|
||||||
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn;
|
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn;
|
||||||
|
SPLIT_LIST *Split;
|
||||||
|
|
||||||
if (PcdGet8(PcdShellSupportLevel) > 3) {
|
if (PcdGet8(PcdShellSupportLevel) > 3) {
|
||||||
return (EFI_UNSUPPORTED);
|
return (EFI_UNSUPPORTED);
|
||||||
|
@ -675,7 +676,17 @@ FreeResources:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsListEmpty(&ShellInfoObject.SplitList.Link)){
|
if (!IsListEmpty(&ShellInfoObject.SplitList.Link)){
|
||||||
ASSERT(FALSE); ///@todo finish this de-allocation.
|
ASSERT(FALSE); ///@todo finish this de-allocation (free SplitStdIn/Out when needed).
|
||||||
|
|
||||||
|
for ( Split = (SPLIT_LIST*)GetFirstNode (&ShellInfoObject.SplitList.Link)
|
||||||
|
; !IsNull (&ShellInfoObject.SplitList.Link, &Split->Link)
|
||||||
|
; Split = (SPLIT_LIST *)GetNextNode (&ShellInfoObject.SplitList.Link, &Split->Link)
|
||||||
|
) {
|
||||||
|
RemoveEntryList (&Split->Link);
|
||||||
|
FreePool (Split);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_CODE (InitializeListHead (&ShellInfoObject.SplitList.Link););
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShellInfoObject.ShellInitSettings.FileName != NULL) {
|
if (ShellInfoObject.ShellInitSettings.FileName != NULL) {
|
||||||
|
@ -1743,11 +1754,12 @@ RunSplitCommand(
|
||||||
//
|
//
|
||||||
// Note that the original StdIn is now the StdOut...
|
// Note that the original StdIn is now the StdOut...
|
||||||
//
|
//
|
||||||
if (Split->SplitStdOut != NULL && Split->SplitStdOut != StdIn) {
|
if (Split->SplitStdOut != NULL) {
|
||||||
ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdOut));
|
ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdOut));
|
||||||
}
|
}
|
||||||
if (Split->SplitStdIn != NULL) {
|
if (Split->SplitStdIn != NULL) {
|
||||||
ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn));
|
ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn));
|
||||||
|
FreePool (Split->SplitStdIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
FreePool(Split);
|
FreePool(Split);
|
||||||
|
|
Loading…
Reference in New Issue