Bug #70078 [Ver]: Memleak when calling PHP functions from XSL with nodes as parameter

From: Date: Wed, 09 Sep 2015 15:50:52 +0000
Subject: Bug #70078 [Ver]: Memleak when calling PHP functions from XSL with nodes as parameter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195918@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70078&edit=1

 ID:                 70078
 Updated by:         mike@php.net
 Reported by:        mplomer at gmx dot de
 Summary:            Memleak when calling PHP functions from XSL with
                     nodes as parameter
 Status:             Verified
 Type:               Bug
 Package:            XSLT related
 Operating System:   any
 PHP Version:        5.6.11
 Block user comment: N
 Private report:     N

 New Comment:

How did you confirm the memleak? Valgrind doesn't complain for me...


Previous Comments:
------------------------------------------------------------------------
[2015-07-15 20:57:01] mplomer at gmx dot de

I also did not understand why exactly the xmlDocCopyNodeList() has been introduced here. IMHO
passing nodes to a PHP function should never implicate such expensive recursive clones.

------------------------------------------------------------------------
[2015-07-15 20:38:43] cmb@php.net

The memory leak (which I can confirm) might be caused by using
xmlDocCopyNodeList() to create a new node list, which would have
to be freed using xmlFreeNodeList() but is actually freed with
xmlFreeNode().

However, I'm not able to reproduce the behavior described in
#49634 with PHP 5.4.23, libxml2-2.7.4 and libxslt-1.1.25
(bug49634.phpt is passing there as well), so I can't go on here
without the risk to reintroduce #49634.

------------------------------------------------------------------------
[2015-07-14 18:58:16] mplomer at gmx dot de

Related To: Bug #49634

------------------------------------------------------------------------
[2015-07-14 18:55:59] mplomer at gmx dot de

Description:
------------
When calling registered PHP functions in XSLTProcessor from a XSL stylesheet with references to
nodes as parameter, you will notice bad performence and - depending on XML structure - a big
memleak.

Test-Script see:
https://gist.github.com/not-implemented/bb41831a4892f1459e5b

Until 5.4.23 you have ~25 MB RAM usage of the process at the end
Starting with 5.4.24 you have ~1030 MB RAM usage of the process at the end

Please notice, that this high usage is NOT covered by memory_get_usage().

When passing a fixed string to the function instead of ".", the problem ist not
reproducable.

This seems to be introduced in Bug #49634 between 5.4.23 and 5.4.24 (or maybe ~5.5.7 and 5.5.8)
where nodes are recursively duplicated now.

Expected result:
----------------
Memory usage ~25 MB RAM

Actual result:
--------------
Memory usage ~1030 MB RAM


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70078&edit=1


Thread (16 messages)

« previous php.bugs (#195918) next »