Skip to content

Fix a SimpleXMLElement cycle through a by-reference property never being collected - #25790

Open
lacatoire wants to merge 2 commits into
php:PHP-8.4from
lacatoire:fix/simplexml-get-gc-tmp-PHP-8.4
Open

lacatoire wants to merge 2 commits into
php:PHP-8.4from
lacatoire:fix/simplexml-get-gc-tmp-PHP-8.4

Conversation

@lacatoire

@lacatoire lacatoire commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

sxe_get_gc() does not expose sxe->tmp to the cycle collector. That zval is handed out by reference for a missing element and can hold the element itself, so such a cycle is never collected (a debug build reports it as a leak at the end of the request). Add it to the GC buffer.

To reproduce

$x = simplexml_load_string('<r/>');
$w = WeakReference::create($x);
$r = &$x->n;
$r = $x;
unset($r, $x);
gc_collect_cycles();
var_dump($w->get() !== null);

Before (PHP 8.4.28): bool(true)
After: bool(false)

…ing collected

sxe_get_gc() did not expose sxe->tmp to the cycle collector. That zval
is handed out by reference for a missing element and can hold the
element itself, so such a cycle was never collected. Add it to the GC
buffer.
Comment thread ext/simplexml/simplexml.c Resolved
Co-authored-by: Nora Dossche <7771979+ndossche@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants