Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Samples/Win7Samples/sysmgmt/msi/setup.exe/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,12 @@ bool AcquireShutdownPrivilege()
// 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.

FreeLibrary(hAdvapi32);
return false;
}

CloseHandle(hToken);
FreeLibrary(hAdvapi32);

return true;
Expand Down