Skip to content

ext/pdo: Fix GC freeing callbacks of a shared persistent connection - #24529

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/pdo-persistent-shared-gc
Open

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/pdo-persistent-shared-gc

Conversation

@iliaal

@iliaal iliaal commented Oct 22, 2026

Copy link
Copy Markdown
Member

PDO reported shared driver callbacks to the GC once per PDO object despite owning only one reference, so two live PDO objects sharing a persistent SQLite connection could free callbacks still in use. Driver callbacks are now reported only when one object owns the connection; cycles through them remain uncollected while it is shared. SQLite is the only bundled driver with this GC hook. Found while testing #24041; verified with pdo_sqlite on PHP-8.4 debug NTS and under valgrind.

Every PDO object attached to a persistent connection shares one pdo_dbh_t,
and dbh_get_gc() reported the driver's GC data once per object. pdo_sqlite
holds each user function, aggregate and collation callback once, so with
two or more objects the collector subtracted more references than exist
and freed live closures, crashing or returning wrong results. Report driver
GC data only while a single object owns the handle, the same refcount check
the rollback guard uses since phpGH-23962. While the connection is shared,
cycles through those callbacks are left to request shutdown, as they already
are with GC disabled. No other bundled driver implements get_gc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant