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@6306 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12
2008-10-30 07:32:46 +00:00
parent bb1d8ee669
commit 676df92c2c
27 changed files with 652 additions and 410 deletions

View File

@@ -712,9 +712,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;
}
@@ -770,8 +776,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;
}
@@ -855,8 +865,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;
}
@@ -1025,8 +1039,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;
}
@@ -1129,8 +1147,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;
}

View File

@@ -445,7 +445,9 @@ DestroyExpression (
OpCode = EXPRESSION_OPCODE_FROM_LINK (Link);
RemoveEntryList (&OpCode->Link);
SafeFreePool (OpCode->ValueList);
if (OpCode->ValueList != NULL) {
FreePool (OpCode->ValueList);
}
}
//
@@ -473,25 +475,41 @@ DestroyStorage (
return;
}
SafeFreePool (Storage->Name);
SafeFreePool (Storage->Buffer);
SafeFreePool (Storage->EditBuffer);
if (Storage->Name != NULL) {
FreePool (Storage->Name);
}
if (Storage->Buffer != NULL) {
FreePool (Storage->Buffer);
}
if (Storage->EditBuffer != NULL) {
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);
if (NameValueNode->Name != NULL) {
FreePool (NameValueNode->Name);
}
if (NameValueNode->Value != NULL) {
FreePool (NameValueNode->Value);
}
if (NameValueNode->EditValue != NULL) {
FreePool (NameValueNode->EditValue);
}
FreePool (NameValueNode);
}
SafeFreePool (Storage->ConfigHdr);
SafeFreePool (Storage->ConfigRequest);
if (Storage->ConfigHdr != NULL) {
FreePool (Storage->ConfigHdr);
}
if (Storage->ConfigRequest != NULL) {
FreePool (Storage->ConfigRequest);
}
gBS->FreePool (Storage);
FreePool (Storage);
}
@@ -555,8 +573,12 @@ DestroyStatement (
DestroyExpression (Expression);
}
SafeFreePool (Statement->VariableName);
SafeFreePool (Statement->BlockName);
if (Statement->VariableName != NULL) {
FreePool (Statement->VariableName);
}
if (Statement->BlockName != NULL) {
FreePool (Statement->BlockName);
}
}
@@ -623,7 +645,7 @@ DestroyFormSet (
//
// Free IFR binary buffer
//
SafeFreePool (FormSet->IfrBinaryData);
FreePool (FormSet->IfrBinaryData);
//
// Free FormSet Storage
@@ -664,10 +686,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

@@ -611,34 +611,34 @@ FreeBrowserStrings (
VOID
)
{
SafeFreePool (gFunctionOneString);
SafeFreePool (gFunctionTwoString);
SafeFreePool (gFunctionNineString);
SafeFreePool (gFunctionTenString);
SafeFreePool (gEnterString);
SafeFreePool (gEnterCommitString);
SafeFreePool (gEscapeString);
SafeFreePool (gMoveHighlight);
SafeFreePool (gMakeSelection);
SafeFreePool (gDecNumericInput);
SafeFreePool (gHexNumericInput);
SafeFreePool (gToggleCheckBox);
SafeFreePool (gPromptForData);
SafeFreePool (gPromptForPassword);
SafeFreePool (gPromptForNewPassword);
SafeFreePool (gConfirmPassword);
SafeFreePool (gPassowordInvalid);
SafeFreePool (gConfirmError);
SafeFreePool (gPressEnter);
SafeFreePool (gEmptyString);
SafeFreePool (gAreYouSure);
SafeFreePool (gYesResponse);
SafeFreePool (gNoResponse);
SafeFreePool (gMiniString);
SafeFreePool (gPlusString);
SafeFreePool (gMinusString);
SafeFreePool (gAdjustNumber);
SafeFreePool (gSaveChanges);
FreePool (gFunctionOneString);
FreePool (gFunctionTwoString);
FreePool (gFunctionNineString);
FreePool (gFunctionTenString);
FreePool (gEnterString);
FreePool (gEnterCommitString);
FreePool (gEscapeString);
FreePool (gMoveHighlight);
FreePool (gMakeSelection);
FreePool (gDecNumericInput);
FreePool (gHexNumericInput);
FreePool (gToggleCheckBox);
FreePool (gPromptForData);
FreePool (gPromptForPassword);
FreePool (gPromptForNewPassword);
FreePool (gConfirmPassword);
FreePool (gPassowordInvalid);
FreePool (gConfirmError);
FreePool (gPressEnter);
FreePool (gEmptyString);
FreePool (gAreYouSure);
FreePool (gYesResponse);
FreePool (gNoResponse);
FreePool (gMiniString);
FreePool (gPlusString);
FreePool (gMinusString);
FreePool (gAdjustNumber);
FreePool (gSaveChanges);
return ;
}

View File

@@ -724,7 +724,9 @@ NewStringCpy (
IN CHAR16 *Src
)
{
SafeFreePool (*Dest);
if (*Dest != NULL) {
FreePool (*Dest);
}
*Dest = AllocateCopyPool (StrSize (Src), Src);
ASSERT (*Dest != NULL);
}
@@ -865,7 +867,9 @@ SetValueByName (
Node = NAME_VALUE_NODE_FROM_LINK (Link);
if (StrCmp (Name, Node->Name) == 0) {
SafeFreePool (Node->EditValue);
if (Node->EditValue != NULL) {
FreePool (Node->EditValue);
}
Node->EditValue = AllocateCopyPool (StrSize (Value), Value);
ASSERT (Node->EditValue != NULL);
return EFI_SUCCESS;

View File

@@ -2137,7 +2137,9 @@ UiDisplayMenu (
gDirection = SCAN_LEFT;
}
Status = ProcessOptions (Selection, MenuOption, TRUE, &OptionString);
SafeFreePool (OptionString);
if (OptionString != NULL) {
FreePool (OptionString);
}
}
break;