#42158 [Opn]: SimpleXMLElement as parameter for preg_match leads to memory leak

From: Date: Tue, 31 Jul 2007 13:19:38 +0000
Subject: #42158 [Opn]: SimpleXMLElement as parameter for preg_match leads to memory leak
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-115601@lists.php.net to get a copy of this message
ID: 42158 User updated by: chabrol at vfnm dot de Reported By: chabrol at vfnm dot de Status: Open Bug Type: PCRE related Operating System: Linux PHP Version: 5CVS-2007-07-31 (snap) New Comment: little imprecision fix: Memory is only increasing until hitting configured memory if you replace the limited for-loop by a while(true) ... Previous Comments: ------------------------------------------------------------------------ [2007-07-31 13:13:45] chabrol at vfnm dot de Description: ------------ If you use a SimpleXMLElement as parameter for preg_match or preg_match_all, memory is lost. P.S.: If you cast the parameter explicit with (string)$xml->name memory usage doesn't increase. So i suppose it's an problem related to internal casting. Reproduce code: --------------- <?php $xml = simplexml_load_string("<root><name>foo</name></root>"); for ($i=1; $i<=20; $i++) { preg_match("/bar/", $xml->name); // or preg_match_all("/bar/", $xml->name, $matches); echo "Memory usage after $i iterations: " . memory_get_usage() . "\n"; } ?> Expected result: ---------------- I would expect an more or less equal memory usage. Actual result: -------------- Memory usage is constantly increasing until hitting configured memory limit ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42158&edit=1

« previous php.bugs (#115601) next »