From 3e8ec9e0561cc52d42a4ea88271b0cac8db569f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sat, 26 Sep 2026 02:15:34 +0000 Subject: [PATCH] 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. --- ext/pdo/pdo_dbh.c | 2 +- .../tests/persistent_connection_failure.phpt | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ext/pdo_pgsql/tests/persistent_connection_failure.phpt 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-- + 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