ShellPkg: Fix NSH parsing

This skips lines in NSH files that are completely comments.  This reduces the memory overhead and the later processing.

This also frees memory correctly when a second memory allocation fails.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Ruiyu Ni <Ruiyu.ni@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15072 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jaben Carsey 2014-01-09 18:02:26 +00:00 committed by jcarsey
parent c1f9c34621
commit 4922715d85
1 changed files with 4 additions and 2 deletions

View File

@ -2362,11 +2362,13 @@ RunScriptFileHandle (
while(!ShellFileHandleEof(Handle)) {
CommandLine = ShellFileHandleReturnLine(Handle, &Ascii);
LineCount++;
if (CommandLine == NULL || StrLen(CommandLine) == 0) {
if (CommandLine == NULL || StrLen(CommandLine) == 0 || CommandLine[0] == '#') {
SHELL_FREE_NON_NULL(CommandLine);
continue;
}
NewScriptFile->CurrentCommand = AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST));
if (NewScriptFile->CurrentCommand == NULL) {
SHELL_FREE_NON_NULL(CommandLine);
DeleteScriptFileStruct(NewScriptFile);
return (EFI_OUT_OF_RESOURCES);
}