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; return Status;
} }

View File

@ -558,8 +558,10 @@ HiiUpdateForm (
Done: Done:
if (UefiHiiUpdateData != NULL) { if (UefiHiiUpdateData != NULL) {
SafeFreePool (UefiHiiUpdateData->Data); if (UefiHiiUpdateData->Data != NULL) {
SafeFreePool (UefiHiiUpdateData); FreePool (UefiHiiUpdateData->Data);
}
FreePool (UefiHiiUpdateData);
} }
mInFrameworkUpdatePakcage = FALSE; mInFrameworkUpdatePakcage = FALSE;

View File

@ -408,7 +408,9 @@ Returns:
Done: Done:
FreePool (LangCodes3066); FreePool (LangCodes3066);
SafeFreePool (LangCodes639); if (LangCodes639 != NULL) {
FreePool (LangCodes639);
}
return Status; return Status;
} }
@ -491,11 +493,18 @@ Returns:
*LanguageString = AsciiStrToUnicodeStr (SecLangCodes639, UnicodeSecLangCodes639); *LanguageString = AsciiStrToUnicodeStr (SecLangCodes639, UnicodeSecLangCodes639);
Done: Done:
if (PrimaryLang639 != NULL) {
SafeFreePool (PrimaryLang639); FreePool (PrimaryLang639);
SafeFreePool (SecLangCodes639); }
SafeFreePool (SecLangCodes3066); if (SecLangCodes639 != NULL) {
SafeFreePool (UnicodeSecLangCodes639); FreePool (SecLangCodes639);
}
if (SecLangCodes3066 != NULL) {
FreePool (SecLangCodes3066);
}
if (UnicodeSecLangCodes639 != NULL) {
FreePool (UnicodeSecLangCodes639);
}
return Status; return Status;
} }

View File

@ -322,7 +322,7 @@ UefiRegisterPackageList(
&ThunkContext->UefiHiiHandle &ThunkContext->UefiHiiHandle
); );
if (Status == EFI_INVALID_PARAMETER) { if (Status == EFI_INVALID_PARAMETER) {
SafeFreePool (PackageListHeader); FreePool (PackageListHeader);
// //
// UEFI HII database does not allow two package list with the same GUID. // UEFI HII database does not allow two package list with the same GUID.
@ -386,7 +386,9 @@ Done:
*Handle = ThunkContext->FwHiiHandle; *Handle = ThunkContext->FwHiiHandle;
} }
SafeFreePool (PackageListHeader); if (PackageListHeader != NULL) {
FreePool (PackageListHeader);
}
return Status; return Status;
} }

View File

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

View File

@ -462,9 +462,9 @@ DestroyDefaultNode (
IN UEFI_IFR_BUFFER_STORAGE_NODE *Node IN UEFI_IFR_BUFFER_STORAGE_NODE *Node
) )
{ {
SafeFreePool (Node->Buffer); FreePool (Node->Buffer);
SafeFreePool (Node->Name); FreePool (Node->Name);
SafeFreePool (Node); FreePool (Node);
} }

View File

@ -386,7 +386,9 @@ DestroyExpression (
OpCode = EXPRESSION_OPCODE_FROM_LINK (Link); OpCode = EXPRESSION_OPCODE_FROM_LINK (Link);
RemoveEntryList (&OpCode->Link); RemoveEntryList (&OpCode->Link);
SafeFreePool (OpCode->ValueList); if (OpCode->ValueList != NULL) {
FreePool (OpCode->ValueList);
}
} }
// //
@ -416,25 +418,25 @@ DestroyStorage (
return; return;
} }
SafeFreePool (Storage->Name); FreePool (Storage->Name);
SafeFreePool (Storage->Buffer); FreePool (Storage->Buffer);
SafeFreePool (Storage->EditBuffer); FreePool (Storage->EditBuffer);
while (!IsListEmpty (&Storage->NameValueListHead)) { while (!IsListEmpty (&Storage->NameValueListHead)) {
Link = GetFirstNode (&Storage->NameValueListHead); Link = GetFirstNode (&Storage->NameValueListHead);
NameValueNode = NAME_VALUE_NODE_FROM_LINK (Link); NameValueNode = NAME_VALUE_NODE_FROM_LINK (Link);
RemoveEntryList (&NameValueNode->Link); RemoveEntryList (&NameValueNode->Link);
SafeFreePool (NameValueNode->Name); FreePool (NameValueNode->Name);
SafeFreePool (NameValueNode->Value); FreePool (NameValueNode->Value);
SafeFreePool (NameValueNode->EditValue); FreePool (NameValueNode->EditValue);
SafeFreePool (NameValueNode); FreePool (NameValueNode);
} }
SafeFreePool (Storage->ConfigHdr); FreePool (Storage->ConfigHdr);
SafeFreePool (Storage->ConfigRequest); FreePool (Storage->ConfigRequest);
gBS->FreePool (Storage); FreePool (Storage);
} }
@ -500,11 +502,16 @@ DestroyStatement (
DestroyExpression (Expression); DestroyExpression (Expression);
} }
SafeFreePool (Statement->VariableName); if (Statement->VariableName != NULL) {
SafeFreePool (Statement->BlockName); FreePool (Statement->VariableName);
}
if (Statement->BlockName != NULL) {
FreePool (Statement->BlockName);
}
} }
/** /**
Free resources of a Form Free resources of a Form
@ -572,7 +579,7 @@ DestroyFormSet (
// //
// Free IFR binary buffer // Free IFR binary buffer
// //
SafeFreePool (FormSet->IfrBinaryData); FreePool (FormSet->IfrBinaryData);
// //
// Free FormSet Storage // Free FormSet Storage
@ -613,10 +620,14 @@ DestroyFormSet (
} }
} }
SafeFreePool (FormSet->StatementBuffer); if (FormSet->StatementBuffer != NULL) {
SafeFreePool (FormSet->ExpressionBuffer); 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); Result->Value.string = NewString (StringPtr, FormSet->HiiHandle);
Done: Done:
SafeFreePool (String[0]); if (String[0] != NULL) {
SafeFreePool (String[1]); FreePool (String[0]);
SafeFreePool (StringPtr); }
if (String[1] != NULL) {
FreePool (String[1]);
}
if (StringPtr != NULL) {
FreePool (StringPtr);
}
return Status; return Status;
} }
@ -790,8 +796,12 @@ IfrMatch (
Result->Value.b = mUnicodeCollation->MetaiMatch (mUnicodeCollation, String[0], String[1]); Result->Value.b = mUnicodeCollation->MetaiMatch (mUnicodeCollation, String[0], String[1]);
Done: Done:
SafeFreePool (String[0]); if (String[0] != NULL) {
SafeFreePool (String[1]); FreePool (String[0]);
}
if (String[1] != NULL) {
FreePool (String[1]);
}
return Status; return Status;
} }
@ -875,8 +885,12 @@ IfrFind (
} }
Done: Done:
SafeFreePool (String[0]); if (String[0] != NULL) {
SafeFreePool (String[1]); FreePool (String[0]);
}
if (String[1] != NULL) {
FreePool (String[1]);
}
return Status; return Status;
} }
@ -1045,8 +1059,12 @@ IfrToken (
Result->Value.string = NewString (SubString, FormSet->HiiHandle); Result->Value.string = NewString (SubString, FormSet->HiiHandle);
Done: Done:
SafeFreePool (String[0]); if (String[0] != NULL) {
SafeFreePool (String[1]); FreePool (String[0]);
}
if (String[1] != NULL) {
FreePool (String[1]);
}
return Status; return Status;
} }
@ -1149,8 +1167,12 @@ IfrSpan (
Result->Value.u64 = StringPtr - String[1]; Result->Value.u64 = StringPtr - String[1];
Done: Done:
SafeFreePool (String[0]); if (String[0] != NULL) {
SafeFreePool (String[1]); FreePool (String[0]);
}
if (String[1] != NULL) {
FreePool (String[1]);
}
return Status; return Status;
} }