move DeleteScriptFileStruct from a private to a public function. This allows for better memory cleanup when errors occur.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10906 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jcarsey
2010-10-04 16:26:29 +00:00
parent 40d7a9cfaa
commit 0ab85bef03
3 changed files with 28 additions and 23 deletions

View File

@ -419,6 +419,17 @@ ShellCommandSetNewScript (
IN SCRIPT_FILE *Script OPTIONAL IN SCRIPT_FILE *Script OPTIONAL
); );
/**
Function to cleanup all memory from a SCRIPT_FILE structure.
@param[in] Script The pointer to the structure to cleanup.
**/
VOID
EFIAPI
DeleteScriptFileStruct (
IN SCRIPT_FILE *Script
);
/** /**
Function to get the current Profile string. Function to get the current Profile string.

View File

@ -767,13 +767,16 @@ DeleteScriptFileStruct (
) )
{ {
UINT8 LoopVar; UINT8 LoopVar;
ASSERT(Script != NULL);
ASSERT(Script->ScriptName != NULL); if (Script == NULL) {
return;
}
for (LoopVar = 0 ; LoopVar < Script->Argc ; LoopVar++) { for (LoopVar = 0 ; LoopVar < Script->Argc ; LoopVar++) {
FreePool(Script->Argv[LoopVar]); SHELL_FREE_NON_NULL(Script->Argv[LoopVar]);
} }
if (Script->Argv != NULL) { if (Script->Argv != NULL) {
FreePool(Script->Argv); SHELL_FREE_NON_NULL(Script->Argv);
} }
Script->CurrentCommand = NULL; Script->CurrentCommand = NULL;
while (!IsListEmpty (&Script->CommandList)) { while (!IsListEmpty (&Script->CommandList)) {
@ -781,16 +784,16 @@ DeleteScriptFileStruct (
if (Script->CurrentCommand != NULL) { if (Script->CurrentCommand != NULL) {
RemoveEntryList(&Script->CurrentCommand->Link); RemoveEntryList(&Script->CurrentCommand->Link);
if (Script->CurrentCommand->Cl != NULL) { if (Script->CurrentCommand->Cl != NULL) {
FreePool(Script->CurrentCommand->Cl); SHELL_FREE_NON_NULL(Script->CurrentCommand->Cl);
} }
if (Script->CurrentCommand->Data != NULL) { if (Script->CurrentCommand->Data != NULL) {
FreePool(Script->CurrentCommand->Data); SHELL_FREE_NON_NULL(Script->CurrentCommand->Data);
} }
FreePool(Script->CurrentCommand); SHELL_FREE_NON_NULL(Script->CurrentCommand);
} }
} }
FreePool(Script->ScriptName); SHELL_FREE_NON_NULL(Script->ScriptName);
FreePool(Script); SHELL_FREE_NON_NULL(Script);
} }
/** /**
@ -833,7 +836,6 @@ ShellCommandSetNewScript (
SCRIPT_FILE_LIST *Node; SCRIPT_FILE_LIST *Node;
if (Script == NULL) { if (Script == NULL) {
if (IsListEmpty (&mScriptList.Link)) { if (IsListEmpty (&mScriptList.Link)) {
ASSERT(FALSE);
return (NULL); return (NULL);
} }
Node = (SCRIPT_FILE_LIST *)GetFirstNode(&mScriptList.Link); Node = (SCRIPT_FILE_LIST *)GetFirstNode(&mScriptList.Link);
@ -842,6 +844,9 @@ ShellCommandSetNewScript (
FreePool(Node); FreePool(Node);
} else { } else {
Node = AllocateZeroPool(sizeof(SCRIPT_FILE_LIST)); Node = AllocateZeroPool(sizeof(SCRIPT_FILE_LIST));
if (Node == NULL) {
return (NULL);
}
Node->Data = Script; Node->Data = Script;
InsertHeadList(&mScriptList.Link, &Node->Link); InsertHeadList(&mScriptList.Link, &Node->Link);
} }
@ -1025,7 +1030,7 @@ ShellCommandCreateInitialMappingsAndPaths(
// //
// Find each handle with Simple File System // Find each handle with Simple File System
// //
HandleList = GetHandleListByPotocol(&gEfiSimpleFileSystemProtocolGuid); HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
if (HandleList != NULL) { if (HandleList != NULL) {
// //
// Do a count of the handles // Do a count of the handles
@ -1085,7 +1090,7 @@ ShellCommandCreateInitialMappingsAndPaths(
// //
// Find each handle with Block Io // Find each handle with Block Io
// //
HandleList = GetHandleListByPotocol(&gEfiBlockIoProtocolGuid); HandleList = GetHandleListByProtocol(&gEfiBlockIoProtocolGuid);
if (HandleList != NULL) { if (HandleList != NULL) {
for (Count = 0 ; HandleList[Count] != NULL ; Count++); for (Count = 0 ; HandleList[Count] != NULL ; Count++);

View File

@ -58,17 +58,6 @@ typedef struct {
SCRIPT_FILE *Data; SCRIPT_FILE *Data;
} SCRIPT_FILE_LIST; } SCRIPT_FILE_LIST;
/**
Function to cleanup all memory from a SCRIPT_FILE structure.
@param[in] Script The pointer to the structure to cleanup.
**/
VOID
EFIAPI
DeleteScriptFileStruct (
IN SCRIPT_FILE *Script
);
typedef struct { typedef struct {
EFI_FILE_PROTOCOL *FileHandle; EFI_FILE_PROTOCOL *FileHandle;
CHAR16 *Path; CHAR16 *Path;