[php-src] PHP-8.6: ext/pdo_pgsql: Fix crash when a persistent connection fails
| From: | 武田 憲太郎 via David Carlier | Date: | Sat, 26 Sep 2026 18:39:14 +0000 |
| Subject: | [php-src] PHP-8.6: ext/pdo_pgsql: Fix crash when a persistent connection fails | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141586@lists.php.net to get a copy of this message | ||
Author: 武田 憲太郎 (KentarouTakeda)
Committer: David Carlier (devnexen)
Date: 2026-09-26T19:38:52+01:00
Commit: https://github.com/php/php-src/commit/5d57dd6140a874204e6a93719fccf3a201500507
Raw diff: https://github.com/php/php-src/commit/5d57dd6140a874204e6a93719fccf3a201500507.diff
ext/pdo_pgsql: Fix crash when a persistent connection fails
The shutdown function tried to reset the session state even when the
connection had failed.
Regression from GH-20572.
Close GH-23922
Changed paths:
A ext/pdo_pgsql/tests/persistent_connection_failure.phpt
M NEWS
M ext/pdo/pdo_dbh.c
Diff:
diff --git a/NEWS b/NEWS
index 40bc06f89e22..5dadee43b6ce 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,9 @@ PHP NEWS
. Fixed pcntl_signal_dispatch() dropping the signals queued behind a handler
that throws. (nicolas-grekas)
+- PDO_PGSQL:
+ . Fixed crash when a persistent connection fails. (KentarouTakeda)
+
24 Sep 2026, PHP 8.6.0RC2
- Core:
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 358ac81eb88f..5aa95cdccaf0 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -1597,7 +1597,7 @@ static void pdo_dbh_free_storage(zend_object *std)
dbh->in_txn = false;
}
- if (dbh->is_persistent && dbh->methods &&
dbh->methods->persistent_shutdown) {
+ if (dbh->is_persistent && dbh->driver_data && dbh->methods &&
dbh->methods->persistent_shutdown) {
dbh->methods->persistent_shutdown(dbh);
}
zend_object_std_dtor(std);
diff --git a/ext/pdo_pgsql/tests/persistent_connection_failure.phpt
b/ext/pdo_pgsql/tests/persistent_connection_failure.phpt
new file mode 100644
index 000000000000..7be690ae05a8
--- /dev/null
+++ b/ext/pdo_pgsql/tests/persistent_connection_failure.phpt
@@ -0,0 +1,21 @@
+--TEST--
+PDO PgSQL failed persistent connection does not crash on object destruction
+--EXTENSIONS--
+pdo_pgsql
+--FILE--
+<?php
+
+try {
+ new Pdo\Pgsql('pgsql:host=/nonexistent', options: [
+ PDO::ATTR_PERSISTENT => true,
+ ]);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), PHP_EOL;
+}
+
+echo "Failed connection object destroyed without crash\n";
+
+?>
+--EXPECTF--
+PDOException: SQLSTATE[08006] [7] %a
+Failed connection object destroyed without crash