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
This commit is contained in:
qwang12 2008-10-30 08:00:56 +00:00
parent 676df92c2c
commit 7001eaf8e5
8 changed files with 93 additions and 43 deletions

View File

@ -508,7 +508,9 @@ ThunkExtractConfig (
);
}
SafeFreePool (Data);
if (Data != NULL) {
FreePool (Data);
}
return Status;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -378,7 +378,9 @@ Returns:
}
Done:
SafeFreePool (Iso639AsciiLanguage);
if (Iso639AsciiLanguage != NULL) {
FreePool (Iso639AsciiLanguage);
}
return Status;
}

View File

@ -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);
}

View File

@ -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,9 +502,14 @@ DestroyStatement (
DestroyExpression (Expression);
}
SafeFreePool (Statement->VariableName);
SafeFreePool (Statement->BlockName);
if (Statement->VariableName != NULL) {
FreePool (Statement->VariableName);
}
if (Statement->BlockName != NULL) {
FreePool (Statement->BlockName);
}
}
/**
@ -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);
}

View File

@ -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;
}