Repository navigation
Initialize thread handle sentinel before starting Windows thread - #218
Merged
michaelrsweet merged 1 commit intoNov 18, 2026
Merged
michaelrsweet merged 1 commit into
michaelrsweet merged 1 commit into
Conversation
win32_wrapper() busy-waits on thread->h == (HANDLE)-1 to avoid tearing down the thread object before cupsThreadCreate() has finished storing the real handle, but the object comes from calloc() so thread->h starts out as 0, not -1 - the sentinel the wait loop checks for was never actually in place during the window it's meant to protect. If the new thread's function returned quickly, win32_wrapper() would see h == 0, conclude the thread was detached, and free the object while cupsThreadCreate() could still be in the middle of writing to it. Set the sentinel before starting the thread so the wait is real.
michaelrsweet
approved these changes
Nov 18, 2026
michaelrsweet
added a commit
that referenced
this pull request
Nov 18, 2026
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
win32_wrapper waits for thread->h to change from (HANDLE)-1 before deciding whether it can free the thread object. Since the object is zero-allocated, that sentinel is not present while _beginthreadex starts the new thread. A fast-returning thread can observe zero, free the object, and race with cupsThreadCreate storing the real handle. Set the sentinel before calling _beginthreadex so the wait protects the handle assignment.