Skip to content

Commit

Permalink
Fix memory leak and also detect failed memory allocation (#1084)
Browse files Browse the repository at this point in the history
## Description

Fixes #632 

This change is responsive to
#632. It fixes a
memory leak and also defends against a failed memory allocation.

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?

## How This Was Tested

Build test and boot to shell using QEMU

## Integration Instructions

N/A
  • Loading branch information
vincent-j-zimmer authored Dec 20, 2024
1 parent a4768f4 commit 575eca8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Platforms/QemuQ35Pkg/ConfigKnobs/ConfigDataGfx/ConfigDataGfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,26 @@ ApplyGfxConfigToPolicy (
GfxEnablePort0 = *(BOOLEAN *)ConfigBuffer;
GfxSiliconPolicy = AllocateCopyPool (sizeof (DefaultQemuGfxPolicy), DefaultQemuGfxPolicy);

if (GfxSiliconPolicy == NULL) {
DEBUG ((DEBUG_ERROR, "Failed to allocate Policy structure\n"));
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}

// We only translate the GFX ports #0 exposed to platform from conf data
GfxSiliconPolicy[0].Power_State_Port = GfxEnablePort0;

Status = SetPolicy (&gPolicyDataGFXGuid, POLICY_ATTRIBUTE_FINALIZED, GfxSiliconPolicy, sizeof (DefaultQemuGfxPolicy));

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a Failed to update GFX policy per configuration data - %r!!!\n", __func__, Status));
ASSERT (FALSE);
goto Exit;
ASSERT_EFI_ERROR (Status);
}

Exit:
if (GfxSiliconPolicy != NULL) {
FreePool (GfxSiliconPolicy);
}

return Status;
}

0 comments on commit 575eca8

Please sign in to comment.