Skip to content

Commit 131eb9e

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix memory leak when edge case is hit when registering xpath callback
2 parents ddf584c + e504ab7 commit 131eb9e

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
. Fixed bug GH-17951 (memory_limit is not always limited by max_memory_limit).
1010
(manuelm)
1111

12+
- DOM:
13+
. Fix memory leak when edge case is hit when registering xpath callback.
14+
(ndossche)
15+
1216
- Opcache:
1317
. Fixed bug GH-20329 (opcache.file_cache broken with full interned string
1418
buffer). (Arnaud)

ext/dom/tests/DOMXPath_callables_errors.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ try {
5757
echo $e->getMessage(), "\n";
5858
}
5959

60+
$x = new class {
61+
public static function dump() {}
62+
};
63+
64+
$classes = get_declared_classes();
65+
66+
try {
67+
$str = str_repeat($classes[count($classes) - 1] . '::dump', random_int(1, 1));
68+
$xpath->registerPhpFunctions([$str]);
69+
} catch (Throwable $e) {
70+
echo $e->getMessage(), "\n";
71+
}
72+
6073
?>
6174
--EXPECT--
6275
DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a callable, function "nonexistent" not found or invalid function name
@@ -67,3 +80,4 @@ DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array with
6780
DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
6881
DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
6982
DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a valid callback name
83+
DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names

ext/dom/xpath_callbacks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ static zend_result php_dom_xpath_callback_ns_update_method_handler(
215215
}
216216
zend_tmp_string_release(tmp_str);
217217
} else {
218+
zend_tmp_string_release(tmp_str);
218219
zend_fcc_dtor(fcc);
219220
efree(fcc);
220221
return FAILURE;

0 commit comments

Comments
 (0)