In the IsMemberOfAdministratorsGroup example in MSDN, there is code like this:
if (!OpenThreadToken (GetCurrentThread(), TOKEN_QUERY|TOKEN_DUPLICATE, TRUE, &hToken))
{
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY|TOKEN_DUPLICATE, &hToken))
{
lastErr = GetLastError();
goto CLEANUP;
}
}
....
CLEANUP:
if (hToken)
{
CloseHandle (hToken);
hToken = NULL; // Set variable to same state as resource.
}
I don't see why we need to try to close the token handle if OpenThreadToken() or OpenProcessToken() fails. Is there a special condition when the two functions fail, but the handle is allocated? Or it is simply a typo (they are human anyway)?