[php-src] PHP-8.4: Fix GH-23962: Don't roll back a persistent PDO handle still in use (#23963)
| From: | Lazizbek Ergashev via GitHub | Date: | Mon, 28 Sep 2026 21:52:49 +0000 |
| Subject: | [php-src] PHP-8.4: Fix GH-23962: Don't roll back a persistent PDO handle still in use (#23963) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141648@lists.php.net to get a copy of this message | ||
Author: Lazizbek Ergashev (lazerg)
Committer: GitHub (web-flow)
Pusher: kamil-tekiela
Date: 2026-09-28T22:52:45+01:00
Commit: https://github.com/php/php-src/commit/31098001226e6a39f251c9ad78328d4c0bf4a231
Raw diff: https://github.com/php/php-src/commit/31098001226e6a39f251c9ad78328d4c0bf4a231.diff
Fix GH-23962: Don't roll back a persistent PDO handle still in use (#23963)
Changed paths:
A ext/pdo_sqlite/tests/gh23962.phpt
M NEWS
M ext/pdo/pdo_dbh.c
Diff:
diff --git a/NEWS b/NEWS
index d36d4b56bfcb..4ea8ab370529 100644
--- a/NEWS
+++ b/NEWS
@@ -92,6 +92,8 @@ PHP NEWS
column index. (Ilia Alshanetsky)
. Fixed PDOStatement::bindColumn() registering a binding for a column name
that is not in the result set. (Ilia Alshanetsky)
+ . Fixed bug GH-23962 (Destroying a persistent PDO instance rolls back a
+ transaction still in use by another instance). (Lazizbek Ergashev)
- Readline:
. Fixed a heap over-read in the interactive shell prompt when cli.prompt is
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 9f3d20745df9..1dc43c2b9728 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -1521,7 +1521,9 @@ static void pdo_dbh_free_storage(zend_object *std)
return;
}
- if (dbh->driver_data && dbh->methods && dbh->methods->rollback
&& pdo_is_in_transaction(dbh)) {
+ /* The persistent list holds one reference, other objects may hold the rest */
+ if (dbh->driver_data && dbh->methods && dbh->methods->rollback
+ && (!dbh->is_persistent || dbh->refcount <= 2) &&
pdo_is_in_transaction(dbh)) {
dbh->methods->rollback(dbh);
dbh->in_txn = false;
}
diff --git a/ext/pdo_sqlite/tests/gh23962.phpt b/ext/pdo_sqlite/tests/gh23962.phpt
new file mode 100644
index 000000000000..d4c1cc4e4e0f
--- /dev/null
+++ b/ext/pdo_sqlite/tests/gh23962.phpt
@@ -0,0 +1,31 @@
+--TEST--
+GH-23962 (Destroying a persistent PDO instance rolls back a transaction still in use by another
instance)
+--CREDITS--
+BoyeMagnus
+--EXTENSIONS--
+pdo_sqlite
+--FILE--
+<?php
+$dsn = 'sqlite::memory:';
+
+$a = new PDO($dsn, null, null, [PDO::ATTR_PERSISTENT => true]);
+$b = new PDO($dsn, null, null, [PDO::ATTR_PERSISTENT => true]);
+
+$b->beginTransaction();
+unset($a);
+var_dump($b->inTransaction());
+var_dump($b->commit());
+
+$b->beginTransaction();
+$b->exec('CREATE TABLE test (a int)');
+unset($b);
+
+$c = new PDO($dsn, null, null, [PDO::ATTR_PERSISTENT => true]);
+var_dump($c->inTransaction());
+var_dump($c->query("SELECT count(*) FROM sqlite_master WHERE name =
'test'")->fetchColumn());
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+int(0)