You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
ClosesGH-22316
0 commit comments