ext/pdo_sqlite: createCollation memory leaks fix.

coming from callback arguments when its return type is incorrect.

close GH-18796
This commit is contained in:
David Carlier 2025-06-07 13:31:55 +01:00
parent c772963c9c
commit 1044558b64
No known key found for this signature in database
GPG key ID: 8486F847B4B94EF1
3 changed files with 31 additions and 3 deletions

View file

@ -0,0 +1,24 @@
--TEST--
Pdo\Sqlite::createCollation() memory leaks on wrong callback return type
--EXTENSIONS--
pdo_sqlite
--FILE--
<?php
declare(strict_types=1);
$db = new Pdo\Sqlite('sqlite::memory:');
$db->exec("CREATE TABLE test (c string)");
$db->exec("INSERT INTO test VALUES('youwontseeme')");
$db->exec("INSERT INTO test VALUES('neither')");
$db->createCollation('NAT', function($a, $b): string { return $a . $b; });
try {
$db->query("SELECT c FROM test ORDER BY c COLLATE NAT");
} catch (\TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
PDO::query(): Return value of the callback must be of type int, string returned