Skip to content

DOM memory leak #17145

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
YuanchengJiang opened this issue Dec 13, 2024 · 2 comments
Closed

DOM memory leak #17145

YuanchengJiang opened this issue Dec 13, 2024 · 2 comments

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
$element = new DOMElement("N", "W", "y");
$attr = new DOMAttr("c" , "n");
$doc = new DOMDocument();
$doc->appendChild($element);
$element->setAttributeNodeNS($attr);
$attr->appendChild($doc->createEntityReference('amp'));
var_dump(get_defined_vars());

Resulted in this output:

==423827==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 6 byte(s) in 3 object(s) allocated from:
    #0 0x6807fd in malloc (/home/phpfuzz/WorkSpace/flowfusion/php-src/sapi/cli/php+0x6807fd)
    #1 0x7f5aae2356e3 in xmlStrndup (/lib/x86_64-linux-gnu/libxml2.so.2+0xe36e3)

SUMMARY: AddressSanitizer: 6 byte(s) leaked in 3 allocation(s).

PHP Version

nightly

Operating System

ubuntu 22.04

@devnexen
Copy link
Member

might be a libxml2 version issue ? cc @nielsdos

@nielsdos
Copy link
Member

might be a libxml2 version issue ? cc @nielsdos

Good guess, but for once this is caused by an issue in PHP, it's a stupid typo in this case.

nielsdos added a commit to nielsdos/php-src that referenced this issue Dec 13, 2024
Because the use of RETURN instead of RETVAL, the freeing code could not
be executed. This only is triggerable if the content of the attribute is
mixed text and entities, so it wasn't noticed earlier.
@nielsdos nielsdos linked a pull request Dec 13, 2024 that will close this issue
nielsdos added a commit to nielsdos/php-src that referenced this issue Dec 13, 2024
Because the use of RETURN instead of RETVAL, the freeing code could not
be executed. This only is triggerable if the content of the attribute is
mixed text and entities, so it wasn't noticed earlier.
nielsdos added a commit that referenced this issue Dec 14, 2024
* PHP-8.4:
  Fix GH-17145: DOM memory leak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants