Click to See Complete Forum and Search --> : PSID Leakage Problem , please check the code


akhin
July 3rd, 2007, 05:23 AM
I am doing everything for allocating and freeing sid structure but it always gives leakages please check the code :

BOOL GetAll (char* sFileOrFolderName )
{
DWORD dwRtnCode = 0;
PSID ownerSid = NULL;

HANDLE hFile;


hFile = CreateFile(
sFileOrFolderName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);

if (hFile == INVALID_HANDLE_VALUE)
{



return FALSE;

}




dwRtnCode = GetSecurityInfo(
hFile,
SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION,
(&ownerSid),
NULL,
NULL,
NULL,
NULL);


if( !ownerSid )
{
CloseHandle(hFile);

return FALSE;
}





LocalFree((HLOCAL)ownerSid);


CloseHandle(hFile);

return TRUE ;

}


int _tmain(int argc, _TCHAR* argv[])
{
while(1)
{
if(!GetAll("d:\\aa.txt"))
{
printf("\nFailed");
}

Sleep(1000);
}
return 0;
}

olivthill
July 3rd, 2007, 08:19 AM
See example at http://msdn2.microsoft.com/en-us/library/aa446629.aspx
Apparently, the structure, pointed to by ownerSID, should be allocated.