Skip to content

Commit 00f4cc3

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 00f4cc3

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎ext/pdo_pgsql/pgsql_driver.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ static void pdo_pgsql_request_shutdown(pdo_dbh_t *dbh)
13971397
PGresult *res;
13981398
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
13991399

1400-
if(H->server) {
1400+
if(H && H->server) {
14011401
res = PQexec(H->server, "DISCARD ALL");
14021402

14031403
if(res) {
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)