Skip to content

Memory leak in xml and dom #14343

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 May 28, 2024 · 1 comment · Fixed by #14347
Closed

Memory leak in xml and dom #14343

YuanchengJiang opened this issue May 28, 2024 · 1 comment · Fixed by #14347

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
$aDOM = new DOMDocument();
$fromdom = new DOMDocument();
$fromdom->loadXML('<data xmlns:ai="http://test.org" ai:attr="namespaced" />');
$attr= $fromdom->firstChild->attributes->item(0);
$att = $aDOM->importNode($attr);
?>

Resulted in this output:

=================================================================
==1967160==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x55568de88c0e in malloc (/usr/local/bin/php+0x1c88c0e) (BuildId: c0213df21908f588a04dfadca2142af951d35e31)
    #1 0x7fe0647a6b0d in xmlNewNs (/lib/x86_64-linux-gnu/libxml2.so.2+0x61b0d) (BuildId: aebf8e42966c3ce475ff9d9d51a762831adcbb61)

Indirect leak of 19 byte(s) in 2 object(s) allocated from:
    #0 0x55568de88c0e in malloc (/usr/local/bin/php+0x1c88c0e) (BuildId: c0213df21908f588a04dfadca2142af951d35e31)
    #1 0x7fe0648287f2 in xmlStrdup (/lib/x86_64-linux-gnu/libxml2.so.2+0xe37f2) (BuildId: aebf8e42966c3ce475ff9d9d51a762831adcbb61)

PHP Version

nightly

Operating System

ubuntu 22.04

@iluuu1994
Copy link
Member

/cc @nielsdos

nielsdos added a commit to nielsdos/php-src that referenced this issue May 28, 2024
If there is no root, the namespace cannot be attached to it,
so we have to attach it to the old list.

This isn't a problem in "new DOM" because namespaces are managed in a
separate structure there.
@nielsdos nielsdos linked a pull request May 28, 2024 that will close this issue
nielsdos added a commit that referenced this issue May 29, 2024
* PHP-8.2:
  Fix bug #47925 again (#14348)
  Fix GH-14343: Memory leak in xml and dom (#14347)
nielsdos added a commit that referenced this issue May 29, 2024
* PHP-8.3:
  Fix bug #47925 again (#14348)
  Fix GH-14343: Memory leak in xml and dom (#14347)
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