Skip to content
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

Fix a bug causing crashes when the NtQueryObject worker thread times out #984

Merged
merged 4 commits into from Mar 4, 2017

Conversation

maxbelanger
Copy link
Contributor

@maxbelanger maxbelanger commented Mar 2, 2017

We've observed that psutil can crash in a call to DeleteFiber when trying to clean up the NtQueryObject thread if it takes too long. Looking at the current implementation, it appears the introduction of ConvertThreadToFiber was intended to prevent memory leaks on Windows XP, where TerminateThread does not release the thread's initial stack (per MSDN).

The crash appears to be caused by a misuse of DeleteFiber, which (it appears) shouldn't be called on a converted thread's "main fiber", as releasing the thread normally is meant to take care of that particular cleanup.TerminateThread is seemingly responsible for releasing the thread's resources including the initial fiber state, so calling DeleteFiber can cause an access violation (equivalent to a double delete).

For a simple fix, this patch just removes the use of a fiber altogether, as psutil no longer supports Windows XP anyways and its use is no longer necessary.

While we're at it, this also fixes the signature of psutil_NtQueryObjectThread (casting to LPTHREAD_START_ROUTINE is considered bad).

@giampaolo
Copy link
Owner

giampaolo commented Mar 3, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants