mirror of https://github.com/acidanthera/audk.git
ShellPkg: Fix memory leak when running Shell script.
When we run following script in Shell: " for %a run (1 200) echo %a memmap endfor " We may find memory leak in system. This patch free buffer in 'BufferToFreeList' to avoid this issue. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin <shumin.qiu@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19521 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
a4f138a412
commit
14810d6b64
|
@ -1276,6 +1276,36 @@ AddBufferToFreeList(
|
||||||
return (Buffer);
|
return (Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a new buffer list and stores the old one to OldBufferList
|
||||||
|
|
||||||
|
@param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
SaveBufferList (
|
||||||
|
OUT LIST_ENTRY *OldBufferList
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CopyMem (OldBufferList, &ShellInfoObject.BufferToFreeList.Link, sizeof (LIST_ENTRY));
|
||||||
|
InitializeListHead (&ShellInfoObject.BufferToFreeList.Link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Restore previous nodes into BufferToFreeList .
|
||||||
|
|
||||||
|
@param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
RestoreBufferList (
|
||||||
|
IN OUT LIST_ENTRY *OldBufferList
|
||||||
|
)
|
||||||
|
{
|
||||||
|
FreeBufferList (&ShellInfoObject.BufferToFreeList);
|
||||||
|
CopyMem (&ShellInfoObject.BufferToFreeList.Link, OldBufferList, sizeof (LIST_ENTRY));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Add a buffer to the Line History List
|
Add a buffer to the Line History List
|
||||||
|
|
||||||
|
@ -2661,6 +2691,7 @@ RunScriptFileHandle (
|
||||||
CONST CHAR16 *CurDir;
|
CONST CHAR16 *CurDir;
|
||||||
UINTN LineCount;
|
UINTN LineCount;
|
||||||
CHAR16 LeString[50];
|
CHAR16 LeString[50];
|
||||||
|
LIST_ENTRY OldBufferList;
|
||||||
|
|
||||||
ASSERT(!ShellCommandGetScriptExit());
|
ASSERT(!ShellCommandGetScriptExit());
|
||||||
|
|
||||||
|
@ -2763,6 +2794,8 @@ RunScriptFileHandle (
|
||||||
PrintBuffSize/sizeof(CHAR16) - 1
|
PrintBuffSize/sizeof(CHAR16) - 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
SaveBufferList(&OldBufferList);
|
||||||
|
|
||||||
//
|
//
|
||||||
// NULL out comments
|
// NULL out comments
|
||||||
//
|
//
|
||||||
|
@ -2897,15 +2930,19 @@ RunScriptFileHandle (
|
||||||
|
|
||||||
ShellCommandRegisterExit(FALSE, 0);
|
ShellCommandRegisterExit(FALSE, 0);
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
|
RestoreBufferList(&OldBufferList);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ShellGetExecutionBreakFlag()) {
|
if (ShellGetExecutionBreakFlag()) {
|
||||||
|
RestoreBufferList(&OldBufferList);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
|
RestoreBufferList(&OldBufferList);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ShellCommandGetExit()) {
|
if (ShellCommandGetExit()) {
|
||||||
|
RestoreBufferList(&OldBufferList);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2924,6 +2961,7 @@ RunScriptFileHandle (
|
||||||
NewScriptFile->CurrentCommand->Reset = TRUE;
|
NewScriptFile->CurrentCommand->Reset = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
RestoreBufferList(&OldBufferList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -382,5 +382,28 @@ TrimSpaces(
|
||||||
IN CHAR16 **String
|
IN CHAR16 **String
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
Create a new buffer list and stores the old one to OldBufferList
|
||||||
|
|
||||||
|
@param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
SaveBufferList (
|
||||||
|
OUT LIST_ENTRY *OldBufferList
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Restore previous nodes into BufferToFreeList .
|
||||||
|
|
||||||
|
@param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
RestoreBufferList (
|
||||||
|
IN OUT LIST_ENTRY *OldBufferList
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //_SHELL_INTERNAL_HEADER_
|
#endif //_SHELL_INTERNAL_HEADER_
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue