Skip to content

[pull] master from php:master#834

Merged
pull[bot] merged 5 commits into
dolfly:masterfrom
php:master
Jun 18, 2026
Merged

[pull] master from php:master#834
pull[bot] merged 5 commits into
dolfly:masterfrom
php:master

Conversation

@pull

@pull pull Bot commented Jun 18, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

iliaal and others added 5 commits June 18, 2026 12:30
Several memory-safety issues in the new Io\Poll API, found by review and
confirmed under valgrind:

- Watcher kept a raw pointer to its Context's php_poll_ctx with no
  reference, so dropping the Context while holding a Watcher left
  remove()/modify() dereferencing freed memory (use-after-free). The
  Context now neutralizes its watchers (active=false, poll_ctx=NULL)
  before it is destroyed, so those calls throw InactiveWatcherException.
- StreamPollHandle took a reference on the stream resource in the
  constructor but never released it, leaking the descriptor for the
  rest of the request. Store the zend_resource and release it in the
  handle cleanup; the php_stream may already be freed by then (e.g.
  the user closed it), so the cleanup must not dereference it.
- Watcher and Context had no get_gc handler, so reference cycles through
  Watcher::$data were uncollectable. Add get_gc for both.
- Context, Watcher and StreamPollHandle were cloneable through the
  default handler, which shallow-copied the backing php_poll_ctx and the
  watcher map by pointer and double-freed them on destruction. Mark all
  three uncloneable.
- Calling __construct() a second time on a Context or StreamPollHandle
  replaced the backing context or handle data without releasing the
  first, leaking it. Throw if the object is already constructed.
- The add(), modify(), remove() and wait() entry points accepted a NULL
  ctx and forwarded it to php_poll_set_error(), which dereferenced it.
  The userland layer already gates on an active context before reaching
  the C API, so assert a non-NULL ctx in those entry points instead.

Closes GH-22316
/* */ comments are ignored by the stub parser.
In Autotools these aren't installed and neither are there any public
headers.
@pull pull Bot locked and limited conversation to collaborators Jun 18, 2026
@pull pull Bot added the ⤵️ pull label Jun 18, 2026
@pull pull Bot merged commit ec84d96 into dolfly:master Jun 18, 2026
1 of 2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants