Wolfgang Schwotzer wolfgang.schwotzer@gmx.net wrote:
size = 0;
GetUserNameW( NULL, &size );
user_name = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR) );
if (!user_name) {
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
if (!GetUserNameW( user_name, &size ))
{
HeapFree( GetProcessHeap(), 0, user_name );
return FALSE;
}
size = 0;
dom_size = 0;
LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
*needed = size;
if (info == NULL)
{
HeapFree( GetProcessHeap(), 0, user_name );
return TRUE;
}
if (len < size)
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
HeapFree( GetProcessHeap(), 0, user_name );
return FALSE;
}
dom_size = 0;
ret = LookupAccountNameW( NULL, user_name, (PSID)info, &size, NULL, &dom_size, &use );
HeapFree( GetProcessHeap(), 0, user_name );
return ret;
}
You need to test return value of every 1st call as well as you do for every next one.