Repository navigation
Add support for freeing handles automatically - #3013
Merged
Merged
Conversation
Kenny Kerr (kennykerr)
requested review from
Chris Denton (ChrisDenton) and
Rafael Rivera (riverar)
April 30, 2024 18:38
This was referenced Apr 30, 2024
Closed
Contributor
|
This looks like really nice stuff! Is the metadata enriched to know when functions like |
Collaborator
Author
This isn't very clear today. Hopefully in future... |
Mateusz Mikuła (mati865)
pushed a commit
to mati865/windows-rs
that referenced
this pull request
Jun 15, 2024
Merged
Mike Griese (zadjii-msft)
pushed a commit
to microsoft/sudo
that referenced
this pull request
Jul 1, 2024
As it happens, another update to the `windows` family of crates is available: https://github.com/microsoft/windows-rs/releases/tag/0.57.0 In particular, this one includes a new feature to support freeing handles automatically: microsoft/windows-rs#3013 This avoids the need for the `OwnedHandle` helper type in Sudo.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Win32 metadata includes information about how to free certain kinds of handles. Since ownership is often unknown or contextual, this is not used to implement the standard
Droptrait. Instead, a newFreetrait provided by thewindows-corecrate is implemented for all handles with appropriate metadata. Thefreefunction can be used to free the handle manually, but anOwned<T>wrapper is provided to callfreeautomatically when the owned handle is dropped.This is supported by nearly 150 different handle types - not just
HANDLE- including various crypto handle types, registry, GDI and USER32 types, and many more.Workarounds are provided for the following Win32 metadata bugs:
RAIIFreeimpliesInvalidHandleValuewin32metadata#1891RAIIFreefunctions have wrong type win32metadata#1892Here's an example.
Before:
After:
The BCrypt test provides a more comprehensive example: e386c51
Previously, the test was just leaking. You can see how
Ownedsupports all kinds of BCrypt handle types through type inference.Related: #2638 #2468 #2222