Fix leak when persistent PDO connection fails

As we don't register the resource, the resource dtor is not called
and will not decrement the refcount.
This commit is contained in:
Nikita Popov 2021-11-16 16:14:29 +01:00
parent 812df2bd8a
commit c02aa46126
2 changed files with 20 additions and 0 deletions

View file

@ -419,6 +419,10 @@ options:
}
/* the connection failed; things will tidy up in free_storage */
if (is_persistent) {
dbh->refcount--;
}
/* XXX raise exception */
zend_restore_error_handling(&zeh);
if (!EG(exception)) {

View file

@ -0,0 +1,16 @@
--TEST--
Failure when creating persistent connection
--EXTENSIONS--
pdo_mysql
--FILE--
<?php
try {
$pdo = new PDO('mysql:host=localhost', 'invalid_user', 'invalid_password', [
PDO::ATTR_PERSISTENT => true,
]);
} catch (PDOException $e) {
echo "Caught\n";
}
?>
--EXPECT--
Caught