Revision: 19521
http://sourceforge.net/p/edk2/code/19521
Author: shenshushi
Date: 2015-12-24 08:14:51 +0000 (Thu, 24 Dec 2015)
Log Message:
-----------
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 <[email protected]>
Reviewed-by: Ruiyu Ni <[email protected]>
Modified Paths:
--------------
trunk/edk2/ShellPkg/Application/Shell/Shell.c
trunk/edk2/ShellPkg/Application/Shell/Shell.h
Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.c 2015-12-24 08:06:28 UTC
(rev 19520)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.c 2015-12-24 08:14:51 UTC
(rev 19521)
@@ -1276,7 +1276,37 @@
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
@param Buffer The line buffer to add.
@@ -2661,6 +2691,7 @@
CONST CHAR16 *CurDir;
UINTN LineCount;
CHAR16 LeString[50];
+ LIST_ENTRY OldBufferList;
ASSERT(!ShellCommandGetScriptExit());
@@ -2763,6 +2794,8 @@
PrintBuffSize/sizeof(CHAR16) - 1
);
+ SaveBufferList(&OldBufferList);
+
//
// NULL out comments
//
@@ -2897,15 +2930,19 @@
ShellCommandRegisterExit(FALSE, 0);
Status = EFI_SUCCESS;
+ RestoreBufferList(&OldBufferList);
break;
}
if (ShellGetExecutionBreakFlag()) {
+ RestoreBufferList(&OldBufferList);
break;
}
if (EFI_ERROR(Status)) {
+ RestoreBufferList(&OldBufferList);
break;
}
if (ShellCommandGetExit()) {
+ RestoreBufferList(&OldBufferList);
break;
}
}
@@ -2924,6 +2961,7 @@
NewScriptFile->CurrentCommand->Reset = TRUE;
}
}
+ RestoreBufferList(&OldBufferList);
}
Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.h
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.h 2015-12-24 08:06:28 UTC
(rev 19520)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.h 2015-12-24 08:14:51 UTC
(rev 19521)
@@ -382,5 +382,28 @@
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_
------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits