From 4922715d85564441d7cf16bac1a1fa67673f6877 Mon Sep 17 00:00:00 2001 From: Jaben Carsey Date: Thu, 9 Jan 2014 18:02:26 +0000 Subject: [PATCH] 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 Reviewed-by: Ruiyu Ni git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15072 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Application/Shell/Shell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 44469baaed..81982f1354 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1067,7 +1067,7 @@ DoShellPrompt ( if (!EFI_ERROR (Status)) { CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL; Status = RunCommand(CmdLine); - } + } // // Done with this command @@ -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); } -- 2.39.2