-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential memory leak in WinVerifyTrust call #18
Comments
Hey @JohnLaTwC! Nice catch! I'll take a look and see if I can get these fixed. Now I'm wondering if there are handles from win32 functions that aren't being closed as well. |
Yea a quick survey shows that I basically don't free any of the buffers created by AllocHGlobal :( |
Also some paths that don't free memory:
throw ([ComponentModel.Win32Exception]$SUCCESS).Message
! Leaks memory due to not calling [System.Runtime.InteropServices.Marshal]::FreeCoTaskMem($Info.pcwszFilePath)
|
Handle leak on error paths: May want to move these try
{
...
- CloseHandle -Handle $hProcess
- CloseHandle -Handle $hToken
}
catch
{
Write-Verbose "Process Token Query: $($proc.Id)"
Write-Verbose $_.Exception.Message
}
+ finally
+ {
+ CloseHandle -Handle $hProcess
+ CloseHandle -Handle $hToken
+ }
Similar handle leak in error path here: - CloseHandle -Handle $hThread
- CloseHandle -Handle $hToken
}
catch
{
if($_.Exception.Message -ne 'OpenThreadToken Error: An attempt was made to reference a token that does not exist')
{
Write-Verbose "Thread Token Handle"
Write-Verbose $_.Exception.Message
}
}
+ finally
+ {
+ CloseHandle -Handle $hThread
+ CloseHandle -Handle $hToken
+ }
|
Missing call to
FreeHGlobal
to free memoryPSReflect-Functions/wintrust/WinVerifyTrust.ps1
Line 120 in 3bdfa4a
Similar issue here with missing
FreeHGlobal
forAllocHGlobal
call:PSReflect-Functions/advapi32/LookupPrivilegeName.ps1
Line 54 in 3bdfa4a
Ditto:
PSReflect-Functions/kernel32/GlobalGetAtomName.ps1
Line 45 in 3bdfa4a
Similar issue in the paths that throw exceptions in
GetIpNetTable.ps1
:PSReflect-Functions/iphlpapi/GetIpNetTable.ps1
Line 107 in 3bdfa4a
Might want to do a pass through the repo for these.
The text was updated successfully, but these errors were encountered: