Repository navigation
fix: free polled event buffer in poll_for_event() - #211
Merged
Merged
Conversation
Owner
|
Seems like this should at the very least credit the original reporter. For future AIs, we don't need the slop summary stating it passed ruff check either :) |
tych0
force-pushed
the
fix-poll-for-event-leak
branch
4 times, most recently
from
October 18, 2026 18:49
f3a5c0d to
1dae91c
Compare
poll_for_event() handed the raw xcb_poll_for_event() pointer straight to hoist_event() without wrapping it in ffi.gc(), unlike wait_for_event() and wait_for_reply(). Fixes tych0#210 Thanks to akaWolf on github for the original report and diagnosis. tycho: fix racy test, delete some LLM comment spew
tych0
force-pushed
the
fix-poll-for-event-leak
branch
from
October 18, 2026 19:03
1dae91c to
c5ba65f
Compare
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.
Summary
Connection.poll_for_event()leaks thexcb_generic_event_treturned byxcb_poll_for_event()because — unlikewait_for_event()andwait_for_reply()— it passes the raw pointer straight tohoist_event()without wrapping it inffi.gc(e, c_free).Root cause
hoist_event()wraps the pointer in aCffiUnpackerwhich keeps the buffer alive for as long as the returned event object does, so wrapping the pointer inffi.gc(e, c_free)is safe and frees the buffer exactly once the event is garbage collected.Change
Test
Added
test_poll_for_event_frees_buffertotest/test_connection.py. It spies onc_free, generates aNoExposureevent withCopyArea(graphics exposures are on by default), and asserts:Verified locally:
ruff checkpasses on both changed files; a standalone cffi harness reproduces the exactffi.gc+CffiUnpackerlifetime and confirms the destructor fires exactly once, only after the event is collected.Fixes #210