From 7001eaf8e5c94dc03446d6edba3d523060b6a346 Mon Sep 17 00:00:00 2001 From: qwang12 Date: Thu, 30 Oct 2008 08:00:56 +0000 Subject: [PATCH] Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its implementation only check if a pointer is NULL. If a garbage pointer is passed in, the gBS->FreePool will still ASSERT in debug build and return error code. It is recommended that module writer should keep track how a pointer is allocated and free it after use. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6307 6f19259b-4bc3-4df7-8a09-765794883524 --- .../FrameworkHiiToUefiHiiThunk/ConfigAccess.c | 4 +- .../FrameworkHiiToUefiHiiThunk/Forms.c | 6 ++- .../FrameworkHiiToUefiHiiThunk/HiiDatabase.c | 21 ++++++--- .../FrameworkHiiToUefiHiiThunk/Package.c | 6 ++- .../FrameworkHiiToUefiHiiThunk/Strings.c | 4 +- .../UefiIfrDefault.c | 6 +-- .../UefiIfrParser.c | 45 ++++++++++++------- .../UefiIfrParserExpression.c | 44 +++++++++++++----- 8 files changed, 93 insertions(+), 43 deletions(-) diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/ConfigAccess.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/ConfigAccess.c index 0955d7faff..0e4125450f 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/ConfigAccess.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/ConfigAccess.c @@ -508,7 +508,9 @@ ThunkExtractConfig ( ); } - SafeFreePool (Data); + if (Data != NULL) { + FreePool (Data); + } return Status; } diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Forms.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Forms.c index 02beec331f..6616526e95 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Forms.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Forms.c @@ -558,8 +558,10 @@ HiiUpdateForm ( Done: if (UefiHiiUpdateData != NULL) { - SafeFreePool (UefiHiiUpdateData->Data); - SafeFreePool (UefiHiiUpdateData); + if (UefiHiiUpdateData->Data != NULL) { + FreePool (UefiHiiUpdateData->Data); + } + FreePool (UefiHiiUpdateData); } mInFrameworkUpdatePakcage = FALSE; diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.c index 845a9f72e0..c6b30cb85a 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/HiiDatabase.c @@ -408,7 +408,9 @@ Returns: Done: FreePool (LangCodes3066); - SafeFreePool (LangCodes639); + if (LangCodes639 != NULL) { + FreePool (LangCodes639); + } return Status; } @@ -491,11 +493,18 @@ Returns: *LanguageString = AsciiStrToUnicodeStr (SecLangCodes639, UnicodeSecLangCodes639); Done: - - SafeFreePool (PrimaryLang639); - SafeFreePool (SecLangCodes639); - SafeFreePool (SecLangCodes3066); - SafeFreePool (UnicodeSecLangCodes639); + if (PrimaryLang639 != NULL) { + FreePool (PrimaryLang639); + } + if (SecLangCodes639 != NULL) { + FreePool (SecLangCodes639); + } + if (SecLangCodes3066 != NULL) { + FreePool (SecLangCodes3066); + } + if (UnicodeSecLangCodes639 != NULL) { + FreePool (UnicodeSecLangCodes639); + } return Status; } diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Package.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Package.c index 5f2aa18b84..d87b2a28d1 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Package.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Package.c @@ -322,7 +322,7 @@ UefiRegisterPackageList( &ThunkContext->UefiHiiHandle ); if (Status == EFI_INVALID_PARAMETER) { - SafeFreePool (PackageListHeader); + FreePool (PackageListHeader); // // UEFI HII database does not allow two package list with the same GUID. @@ -386,7 +386,9 @@ Done: *Handle = ThunkContext->FwHiiHandle; } - SafeFreePool (PackageListHeader); + if (PackageListHeader != NULL) { + FreePool (PackageListHeader); + } return Status; } diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c index c648e1da1a..5c499392fe 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c @@ -378,7 +378,9 @@ Returns: } Done: - SafeFreePool (Iso639AsciiLanguage); + if (Iso639AsciiLanguage != NULL) { + FreePool (Iso639AsciiLanguage); + } return Status; } diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrDefault.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrDefault.c index 4c382d4eef..f799dc664a 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrDefault.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrDefault.c @@ -462,9 +462,9 @@ DestroyDefaultNode ( IN UEFI_IFR_BUFFER_STORAGE_NODE *Node ) { - SafeFreePool (Node->Buffer); - SafeFreePool (Node->Name); - SafeFreePool (Node); + FreePool (Node->Buffer); + FreePool (Node->Name); + FreePool (Node); } diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrParser.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrParser.c index 8870128ad2..8b130af45f 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrParser.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrParser.c @@ -386,7 +386,9 @@ DestroyExpression ( OpCode = EXPRESSION_OPCODE_FROM_LINK (Link); RemoveEntryList (&OpCode->Link); - SafeFreePool (OpCode->ValueList); + if (OpCode->ValueList != NULL) { + FreePool (OpCode->ValueList); + } } // @@ -416,25 +418,25 @@ DestroyStorage ( return; } - SafeFreePool (Storage->Name); - SafeFreePool (Storage->Buffer); - SafeFreePool (Storage->EditBuffer); + FreePool (Storage->Name); + FreePool (Storage->Buffer); + FreePool (Storage->EditBuffer); while (!IsListEmpty (&Storage->NameValueListHead)) { Link = GetFirstNode (&Storage->NameValueListHead); NameValueNode = NAME_VALUE_NODE_FROM_LINK (Link); RemoveEntryList (&NameValueNode->Link); - SafeFreePool (NameValueNode->Name); - SafeFreePool (NameValueNode->Value); - SafeFreePool (NameValueNode->EditValue); - SafeFreePool (NameValueNode); + FreePool (NameValueNode->Name); + FreePool (NameValueNode->Value); + FreePool (NameValueNode->EditValue); + FreePool (NameValueNode); } - SafeFreePool (Storage->ConfigHdr); - SafeFreePool (Storage->ConfigRequest); + FreePool (Storage->ConfigHdr); + FreePool (Storage->ConfigRequest); - gBS->FreePool (Storage); + FreePool (Storage); } @@ -500,11 +502,16 @@ DestroyStatement ( DestroyExpression (Expression); } - SafeFreePool (Statement->VariableName); - SafeFreePool (Statement->BlockName); + if (Statement->VariableName != NULL) { + FreePool (Statement->VariableName); + } + if (Statement->BlockName != NULL) { + FreePool (Statement->BlockName); + } } + /** Free resources of a Form @@ -572,7 +579,7 @@ DestroyFormSet ( // // Free IFR binary buffer // - SafeFreePool (FormSet->IfrBinaryData); + FreePool (FormSet->IfrBinaryData); // // Free FormSet Storage @@ -613,10 +620,14 @@ DestroyFormSet ( } } - SafeFreePool (FormSet->StatementBuffer); - SafeFreePool (FormSet->ExpressionBuffer); + if (FormSet->StatementBuffer != NULL) { + FreePool (FormSet->StatementBuffer); + } + if (FormSet->ExpressionBuffer != NULL) { + FreePool (FormSet->ExpressionBuffer); + } - SafeFreePool (FormSet); + FreePool (FormSet); } diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrParserExpression.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrParserExpression.c index caeb576336..1fc398fed2 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrParserExpression.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/UefiIfrParserExpression.c @@ -732,9 +732,15 @@ IfrCatenate ( Result->Value.string = NewString (StringPtr, FormSet->HiiHandle); Done: - SafeFreePool (String[0]); - SafeFreePool (String[1]); - SafeFreePool (StringPtr); + if (String[0] != NULL) { + FreePool (String[0]); + } + if (String[1] != NULL) { + FreePool (String[1]); + } + if (StringPtr != NULL) { + FreePool (StringPtr); + } return Status; } @@ -790,8 +796,12 @@ IfrMatch ( Result->Value.b = mUnicodeCollation->MetaiMatch (mUnicodeCollation, String[0], String[1]); Done: - SafeFreePool (String[0]); - SafeFreePool (String[1]); + if (String[0] != NULL) { + FreePool (String[0]); + } + if (String[1] != NULL) { + FreePool (String[1]); + } return Status; } @@ -875,8 +885,12 @@ IfrFind ( } Done: - SafeFreePool (String[0]); - SafeFreePool (String[1]); + if (String[0] != NULL) { + FreePool (String[0]); + } + if (String[1] != NULL) { + FreePool (String[1]); + } return Status; } @@ -1045,8 +1059,12 @@ IfrToken ( Result->Value.string = NewString (SubString, FormSet->HiiHandle); Done: - SafeFreePool (String[0]); - SafeFreePool (String[1]); + if (String[0] != NULL) { + FreePool (String[0]); + } + if (String[1] != NULL) { + FreePool (String[1]); + } return Status; } @@ -1149,8 +1167,12 @@ IfrSpan ( Result->Value.u64 = StringPtr - String[1]; Done: - SafeFreePool (String[0]); - SafeFreePool (String[1]); + if (String[0] != NULL) { + FreePool (String[0]); + } + if (String[1] != NULL) { + FreePool (String[1]); + } return Status; } -- 2.39.2