Bug #73612 [NEW]: preg_*() may leak memory
| From: | cmb@php.net | Date: | Sat, 26 Nov 2016 14:12:51 +0000 |
| Subject: | Bug #73612 [NEW]: preg_*() may leak memory | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-205650@lists.php.net to get a copy of this message | ||
From: cmb
Operating system: *
PHP version: 7.0Git-2016-11-26 (Git)
Package: PCRE related
Bug Type: Bug
Bug description:preg_*() may leak memory
Description:
------------
As has been pointed out by Nikita[1], as of PHP 7.0.0 zval_dtor()
is actually the same as zval_ptr_dtor_nogc(). Therefore
preg_match() and some other PCRE functions may leak memory if
objects are passed as $matches and $count, respectively.
[1] <http://news.php.net/php.internals/97197>
Test script:
---------------
<?php
$obj = new stdClass;
$obj->obj = $obj;
preg_match('/./', 'x', $obj);
$obj = new stdClass;
$obj->obj = $obj;
preg_replace('/./', '', 'x', -1, $obj);
$obj = new stdClass;
$obj->obj = $obj;
preg_replace_callback('/./', 'array_merge', 'x', -1, $obj);
$obj = new stdClass;
$obj->obj = $obj;
preg_replace_callback_array(['/./' => 'array_merge'], 'x', -1,
$obj);
$obj = new stdClass;
$obj->obj = $obj;
preg_filter('/./', '', 'x', -1, $obj);
Actual result:
--------------
[Sat Nov 26 14:03:38 2016] Script: '/vagrant/leak.php'
/vagrant/php-src/Zend/zend_objects.c(162) : Freeing 0x7FF12465ECD0 (40
bytes), script=/vagrant/leak.php
Last leak repeated 4 times
=== Total 5 memory leaks detected ===
--
Edit bug report at https://bugs.php.net/bug.php?id=73612&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73612&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73612&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73612&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73612&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73612&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73612&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73612&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73612&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73612&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73612&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73612&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73612&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73612&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73612&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73612&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73612&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73612&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73612&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73612&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73612&r=mysqlcfg