From 6b6aa6d136067a3c9199b4413cdceb652a823b80 Mon Sep 17 00:00:00 2001 From: Sergei Antonov Date: Thu, 19 Sep 2013 17:23:10 +0000 Subject: [PATCH] ShellPkg: Handle pool allocation failure If AllocateZeroPool() returns NULL, GetVariable() will return EFI_BUFFER_TOO_SMALL, FreePool() will receive NULL. So check for NULL before FreePool(). Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Sergei Antonov Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14688 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c index 8d26c9d93b..7c3aa542b4 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -176,7 +176,9 @@ ShellCommandRunSetVar ( if (Status == EFI_BUFFER_TOO_SMALL) { Buffer = AllocateZeroPool(Size); Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes2, &Size, Buffer); - FreePool(Buffer); + if (Buffer != NULL) { + FreePool(Buffer); + } Attributes = Attributes2; } //