Leakage Problem , please check code



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;
}

.



Relevant Pages

  • Re: Leakage Problem , please check code
    ... A pointer to a variable that receives a pointer to the owner ... DWORD dwRtnCode = 0; ... PSID ownerSid = NULL; ... HANDLE hFile = 0; ...
    (microsoft.public.win32.programmer.kernel)
  • Can there be any bug in GetSecurityInfo ?
    ... BOOL GetAll (char* sFileOrFolderName) ... DWORD dwRtnCode = 0; ... HANDLE hFile; ...
    (microsoft.public.platformsdk.security)
  • RE: Can there be any bug in GetSecurityInfo ?
    ... if CreateFile fails you don't free the allocated memory and your code ... BOOL GetAll (char* sFileOrFolderName) ... DWORD dwRtnCode = 0; ... HANDLE hFile; ...
    (microsoft.public.platformsdk.security)