ext/dom: Fix Dom\Notation nodes missing tree connection#21868
Closed
jordikroon wants to merge 5 commits intophp:masterfrom
Closed
ext/dom: Fix Dom\Notation nodes missing tree connection#21868jordikroon wants to merge 5 commits intophp:masterfrom
jordikroon wants to merge 5 commits intophp:masterfrom
Conversation
b5f92c2 to
fe554cf
Compare
Member
|
I have a memory leak with this test <?php
$xml = <<<XML
<!DOCTYPE root [
<!NOTATION GIF SYSTEM "image/gif">
<!NOTATION JPEG PUBLIC "-//W3C//NOTATION JPEG//EN" "image/jpeg">
]>
<root/>
XML;
$dom = Dom\XMLDocument::createFromString($xml);
for ($i = 0; $i < 3; $i++) {
$n = $dom->doctype->notations->getNamedItem('GIF');
$n = $dom->doctype->notations->getNamedItem('JPEG');
unset($n);
}==243031==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 864 byte(s) in 6 object(s) allocated from:
#0 0x55d3990a8398 in malloc (/tmp/php-src/sapi/cli/php+0x4a8398) (BuildId: 1c230b699569f9967bf81ebb00a650988950221d)
#1 0x55d399389278 in create_notation /tmp/php-src/ext/dom/dom_iterators.c:59:21
#2 0x55d3993e3f91 in dom_map_get_ns_named_item_notation /tmp/php-src/ext/dom/obj_map.c:509:10
#3 0x55d3993e27a3 in php_dom_obj_map_get_ns_named_item_into_zval /tmp/php-src/ext/dom/obj_map.c:482:24
#4 0x55d3993bfd49 in zim_DOMNamedNodeMap_getNamedItem /tmp/php-src/ext/dom/namednodemap.c:64:2
#5 0x55d39a4f4ed5 in ZEND_DO_FCALL_SPEC_RETVAL_USED_TAILCALL_HANDLER /tmp/php-src/Zend/zend_vm_execute.h:54920:4
#6 0x55d39a2766a3 in execute_ex /tmp/php-src/Zend/zend_vm_execute.h:110168:12
#7 0x55d39a276eef in zend_execute /tmp/php-src/Zend/zend_vm_execute.h:115586:2
#8 0x55d39a7f69f0 in zend_execute_script /tmp/php-src/Zend/zend.c:1971:3
#9 0x55d399f23b3f in php_execute_script_ex /tmp/php-src/main/main.c:2646:13
#10 0x55d399f240d8 in php_execute_script /tmp/php-src/main/main.c:2686:9
#11 0x55d39a7fc7ed in do_cli /tmp/php-src/sapi/cli/php_cli.c:947:5
#12 0x55d39a7fac57 in main /tmp/php-src/sapi/cli/php_cli.c:1370:18
#13 0x7fe8f65bbf76 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#14 0x7ffdc955bfe7 (<unknown module>) |
Member
|
hint: XML_NOTATION_NODE. |
Contributor
Author
|
Good catch. Technically this memory leak existed before, but it didn't surface because parent and doc were NULL. |
Member
|
look nice, I ll have a better look this week-end. |
devnexen
reviewed
Apr 25, 2026
devnexen
reviewed
Apr 25, 2026
Co-authored-by: David CARLIER <devnexen@gmail.com>
devnexen
approved these changes
Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an existing TODO by @ndossche.
Notation nodes returned from
$doctype->notationswere not linked to their owning document or parentDocumentType. This caused several incorrect behaviour; including:ownerDocumentwas missingparentNodewasNULLisConnectedreturnedfalsebaseURIfell back to"about:blank"textContentreturned an empty string instead ofNULLThe last point is a violation of the DOM specification. Since
Notationis not anElement,CharacterData,Attr, orDocumentFragment, itstextContentmust returnNULL.Spec reference: https://dom.spec.whatwg.org/#dom-node-textcontent