Skip to content
Open
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ PHP NEWS
the null namespace in spec-following mode. (Ilia Alshanetsky)
. Fixed stale getElementsByClassName() and other node list caches after
className/classList writes and attribute removals. (Ilia Alshanetsky)
. Fixed a reference cycle through DOMXPath php:function callback
arguments not being collectable. (Ilia Alshanetsky)

- Hash:
. Fixed hash_file() reporting argument #1 ($algo) instead of argument #2
Expand Down
28 changes: 28 additions & 0 deletions ext/dom/tests/DOMXPath_callback_node_list_gc.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
DOMXPath callback node list is reported to the cycle collector
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument();
$doc->loadXML('<r><a/></r>');
$xp = new DOMXPath($doc);
$xp->registerNamespace('php', 'http://php.net/xpath');
$xp->registerPhpFunctions();

function cb($n) {
@$n[0]->back = $GLOBALS['the_xp'];
return true;
}

$GLOBALS['the_xp'] = $xp;
$wr = WeakReference::create($xp);
$xp->query('/r/a[php:function("cb", .)]');

unset($xp, $GLOBALS['the_xp']);
gc_collect_cycles();

var_dump($wr->get() === null);
?>
--EXPECT--
bool(true)
8 changes: 7 additions & 1 deletion ext/dom/xpath_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ static void php_dom_xpath_callback_ns_get_gc(php_dom_xpath_callback_ns *ns, zend

PHP_DOM_EXPORT void php_dom_xpath_callbacks_get_gc(php_dom_xpath_callbacks *registry, zend_get_gc_buffer *gc_buffer)
{
if (registry->node_list) {
zval *entry;
ZEND_HASH_FOREACH_VAL(registry->node_list, entry) {
zend_get_gc_buffer_add_zval(gc_buffer, entry);
} ZEND_HASH_FOREACH_END();
}
if (registry->php_ns) {
php_dom_xpath_callback_ns_get_gc(registry->php_ns, gc_buffer);
}
Expand All @@ -113,7 +119,7 @@ PHP_DOM_EXPORT void php_dom_xpath_callbacks_get_gc(php_dom_xpath_callbacks *regi

PHP_DOM_EXPORT HashTable *php_dom_xpath_callbacks_get_gc_for_whole_object(php_dom_xpath_callbacks *registry, zend_object *object, zval **table, int *n)
{
if (registry->php_ns || registry->namespaces) {
if (registry->php_ns || registry->namespaces || registry->node_list) {
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
php_dom_xpath_callbacks_get_gc(registry, gc_buffer);
zend_get_gc_buffer_use(gc_buffer, table, n);
Expand Down
Loading