From fa7b3168fdfc8744f658a5ba5c4e433fc0ae7c82 Mon Sep 17 00:00:00 2001 From: qwang12 Date: Tue, 20 Jan 2009 02:00:46 +0000 Subject: K8: 1) Add in "check-for-null" before dereferencing a pointer. 2) unify the handling of EFI_OUT_OF_RESOURCE case. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7310 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'MdeModulePkg/Library/UefiHiiLib') diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index f5544d9fce..83e33d2a6e 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -281,13 +281,13 @@ HiiLibGetHiiHandles ( OUT EFI_HII_HANDLE **HiiHandleBuffer ) { - UINTN BufferLength; EFI_STATUS Status; ASSERT (HandleBufferLength != NULL); ASSERT (HiiHandleBuffer != NULL); - BufferLength = 0; + *HandleBufferLength = 0; + *HiiHandleBuffer = NULL; // // Try to find the actual buffer size for HiiHandle Buffer. @@ -296,27 +296,26 @@ HiiLibGetHiiHandles ( mHiiDatabaseProt, EFI_HII_PACKAGE_TYPE_ALL, NULL, - &BufferLength, + HandleBufferLength, *HiiHandleBuffer ); - + if (Status == EFI_BUFFER_TOO_SMALL) { - *HiiHandleBuffer = AllocateZeroPool (BufferLength); + *HiiHandleBuffer = AllocateZeroPool (*HandleBufferLength); ASSERT (*HiiHandleBuffer != NULL); Status = mHiiDatabaseProt->ListPackageLists ( mHiiDatabaseProt, EFI_HII_PACKAGE_TYPE_ALL, NULL, - &BufferLength, + HandleBufferLength, *HiiHandleBuffer ); - // - // we should not fail here. - // - ASSERT_EFI_ERROR (Status); - } - *HandleBufferLength = BufferLength; + if (EFI_ERROR (Status)) { + FreePool (*HiiHandleBuffer); + *HiiHandleBuffer = NULL; + } + } return Status; } -- cgit v1.2.3