Fix a bug causing crashes when the NtQueryObject
worker thread times out
#984
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We've observed that
psutil
can crash in a call toDeleteFiber
when trying to clean up theNtQueryObject
thread if it takes too long. Looking at the current implementation, it appears the introduction ofConvertThreadToFiber
was intended to prevent memory leaks on Windows XP, whereTerminateThread
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 callingDeleteFiber
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 toLPTHREAD_START_ROUTINE
is considered bad).