Skip to content

Commit b72dccb

Browse files
committed
Merge branch 'PHP-8.4'
2 parents d15c61e + 1044558 commit b72dccb

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

ext/pdo_sqlite/pdo_sqlite.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ static int php_sqlite_collation_callback(void *context, int string1_len, const v
376376

377377
zend_call_known_fcc(&collation->callback, &retval, /* argc */ 2, zargs, /* named_params */ NULL);
378378

379+
zval_ptr_dtor(&zargs[0]);
380+
zval_ptr_dtor(&zargs[1]);
381+
379382
if (!Z_ISUNDEF(retval)) {
380383
if (Z_TYPE(retval) != IS_LONG) {
381384
zend_string *func_name = get_active_function_or_method_name();
@@ -392,9 +395,6 @@ static int php_sqlite_collation_callback(void *context, int string1_len, const v
392395
}
393396
}
394397

395-
zval_ptr_dtor(&zargs[0]);
396-
zval_ptr_dtor(&zargs[1]);
397-
398398
return ret;
399399
}
400400

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Pdo\Sqlite::createCollation() memory leaks on wrong callback return type
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--FILE--
6+
<?php
7+
8+
declare(strict_types=1);
9+
10+
$db = new Pdo\Sqlite('sqlite::memory:');
11+
12+
$db->exec("CREATE TABLE test (c string)");
13+
$db->exec("INSERT INTO test VALUES('youwontseeme')");
14+
$db->exec("INSERT INTO test VALUES('neither')");
15+
$db->createCollation('NAT', function($a, $b): string { return $a . $b; });
16+
17+
try {
18+
$db->query("SELECT c FROM test ORDER BY c COLLATE NAT");
19+
} catch (\TypeError $e) {
20+
echo $e->getMessage(), PHP_EOL;
21+
}
22+
?>
23+
--EXPECT--
24+
PDO::query(): Return value of the callback must be of type int, string returned

0 commit comments

Comments
 (0)