Skip to content

Fix memory leaks in DevicePathFromText #1525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2025
Merged

Conversation

nicholasbishop
Copy link
Member

The methods of both DevicePathToText and DevicePathFromText return memory that is allocated internally by UEFI, so it needs to be freed on drop. DevicePathToText already does that correctly by returning a PoolString, but this was missed in DevicePathFromText, which just returns a reference.

Fix by adding PoolDevicePath and PoolDevicePathNode structs, and return them from the corresponding methods of DevicePathFromText.

Also add an PoolAllocation struct to reduce code duplication. I've kept this type internal for now, as we might want to introduce a more generic pool allocation struct in the future so that we don't need separate type definitions for PoolString, PoolDevicePath, PoolDevicePathNode, etc. But that would take some more thought to get the API right, so for now these simple additions seem like the most straightforward fix.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This is in preparation for adding a PoolDevicePath type, which will also use
PoolAllocation.
The methods of both DevicePathToText and DevicePathFromText return memory that
is allocated internally by UEFI, so it needs to be freed on
drop. DevicePathToText already does that correctly by returning a `PoolString`,
but this was missed in DevicePathFromText, which just returns a reference.

Fix by adding PoolDevicePath and PoolDevicePathNode structs, and return them
from the corresponding methods of DevicePathFromText.
@nicholasbishop nicholasbishop added this pull request to the merge queue Jan 24, 2025
Merged via the queue into main with commit e4921c1 Jan 24, 2025
18 checks passed
@nicholasbishop nicholasbishop deleted the bishop-dp-convert-free branch January 24, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants