I got tired of trying to find a way to post a bug to the VC team. I saw before you could submit a bug but I cannot find it now. So here it is what I think is a bug:

I have a program that I am making using VC 2005 and ATL. The process starts out impersonating on the main thread. When I run the program in release all is good, but in debug mode it behaves weirdly. I have traced the issue to a call that happens only with the debug version of ATL.

The code is in:

\Microsoft Visual Studio 8\VC\atlmfc\src\atl\atls\Allocate.cpp

BOOL bOpen = OpenThreadToken(GetCurrentThread(), TOKEN_IMPERSONATE|TOKEN_DUPLICATE, TRUE, &hThreadToken);
if( !bOpen || hThreadToken != NULL )
if( !RevertToSelf() )
hThreadToken = NULL;

Note that the if (!bOpen..) block executes in all cases because OpenThreadToken sets the last parameter (hThreadToken) to NULL when it fails. At this point it all goes bad since the if block assumes that it has a non-NULL hThreadToken.

Basicall ATL calling ReverToSelf even when the OpenThreadToken failed is a bug. I assume the developer meant:

if ( bOpen && (NULL != hThreadToken))



Re: Visual C++ General possible bug in ATL (impersonation)

Bruno van Dooren


You can post bugs to

If you post the link here we can rate it and vote on it.

Re: Visual C++ General possible bug in ATL (impersonation)


Thanks. I already did that. Here is the link: FeedbackID=283324