Skip to content

Commit 3e8ec9e

Browse files
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.
1 parent 60ddc8f commit 3e8ec9e

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎ext/pdo/pdo_dbh.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ static void pdo_dbh_free_storage(zend_object *std)
15971597
dbh->in_txn = false;
15981598
}
15991599

1600-
if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) {
1600+
if (dbh->is_persistent && dbh->driver_data && dbh->methods && dbh->methods->persistent_shutdown) {
16011601
dbh->methods->persistent_shutdown(dbh);
16021602
}
16031603
zend_object_std_dtor(std);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
PDO PgSQL failed persistent connection does not crash on object destruction
3+
--EXTENSIONS--
4+
pdo_pgsql
5+
--FILE--
6+
<?php
7+
8+
try {
9+
new Pdo\Pgsql('pgsql:host=/nonexistent', options: [
10+
PDO::ATTR_PERSISTENT => true,
11+
]);
12+
} catch (Throwable $e) {
13+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
14+
}
15+
16+
echo "Failed connection object destroyed without crash\n";
17+
18+
?>
19+
--EXPECTF--
20+
PDOException: SQLSTATE[08006] [7] %a
21+
Failed connection object destroyed without crash

0 commit comments

Comments
 (0)