Skip to content

Commit be3c56d

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

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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)