Skip to content

Fix GH-11347: Memory leak when calling a static method inside an xpath query #11350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ext/dom/tests/gh11347.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-11347 (Memory leak when calling a static method inside an xpath query)
--EXTENSIONS--
dom
--FILE--
<?php

class MyClass
{
public static function dump(string $var) {
var_dump($var);
}
}

$doc = new DOMDocument();
$doc->loadHTML('<a href="https://php.net">hello</a>');
$xpath = new DOMXpath($doc);
$xpath->registerNamespace("php", "http://php.net/xpath");
$xpath->registerPHPFunctions();
$xpath->query("//a[php:function('MyClass::dump', string(@href))]");

?>
Done
--EXPECT--
string(15) "https://php.net"
Done
2 changes: 1 addition & 1 deletion ext/dom/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
}
cleanup:
zend_string_release_ex(callable, 0);
zval_ptr_dtor_str(&fci.function_name);
zval_ptr_dtor_nogc(&fci.function_name);
if (fci.param_count > 0) {
for (i = 0; i < nargs - 1; i++) {
zval_ptr_dtor(&fci.params[i]);
Expand Down