Skip to content

Commit a4da60f

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix leak when persistent PDO connection fails
2 parents f51eb15 + c02aa46 commit a4da60f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ PHP_METHOD(PDO, __construct)
419419
}
420420

421421
/* the connection failed; things will tidy up in free_storage */
422+
if (is_persistent) {
423+
dbh->refcount--;
424+
}
425+
422426
/* XXX raise exception */
423427
zend_restore_error_handling(&zeh);
424428
if (!EG(exception)) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Failure when creating persistent connection
3+
--EXTENSIONS--
4+
pdo_mysql
5+
--FILE--
6+
<?php
7+
try {
8+
$pdo = new PDO('mysql:host=localhost', 'invalid_user', 'invalid_password', [
9+
PDO::ATTR_PERSISTENT => true,
10+
]);
11+
} catch (PDOException $e) {
12+
echo "Caught\n";
13+
}
14+
?>
15+
--EXPECT--
16+
Caught

0 commit comments

Comments
 (0)