Skip to content

Conversation

@RatinCN
Copy link

@RatinCN RatinCN commented Nov 13, 2024

The access token handle returned by OpenProcessToken should be closed when no longer needed.

// cannot test return value of AdjustTokenPrivileges
if (ERROR_SUCCESS != WIN::GetLastError())
{
CloseHandle(hToken);
Copy link
Member

Choose a reason for hiding this comment

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

fix looks correct, using wil::unique_handle (is there wil::unique_htoken?) and RAII for all of the resource lifetimes would simplify further.

Copy link
Author

Choose a reason for hiding this comment

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

The code is too old, I guess here wil is unavailable, but that doesn't matter, an explicit call to CloseHandle can emphasize that it needs to be released. As an example, I think it is more important to show how to use this API.

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