From:             [EMAIL PROTECTED]
Operating system: linux
PHP version:      4.1.1
PHP Bug Type:     Class/Object related
Bug description:  memory leak when passing object

I found a serious memory leaks which occures when passing 
objects. I have included two small code snipplets which 
will reproduce the leak:


Code Snipplet-1: 

memory leak when passing $this object.

<?php
 
 
class Tok {
 
  var $_filter = array();
 
  function filter($name, &$obj) {
    $this->_filter[$name] =& $obj;
  }
 
}
 
 
class A {
 
  var $_tok;
 
  function A() {
    $this->_tok = new Tok();
    $this->_tok->filter('xyz', $this); // memory leak
  }
 
}
 
 
$a = new A();
 
?>

Leak message in error.log:

zend_hash.c(260) :  Freeing 0x08210544 (39 bytes), 
script=/home/share/server/test/index2.php
Last leak repeated 2 times
zend_hash.c(176) :  Freeing 0x082104F4 (32 bytes), 
script=/home/share/server/test/index2.php
Last leak repeated 2 times
./zend_execute.c(753) :  Freeing 0x08210494 (44 bytes), 
script=/home/share/server/test/index2.php
zend_variables.c(117) : Actual location (location was 
relayed)
Last leak repeated 1 time
zend_API.c(593) :  Freeing 0x0821019C (44 bytes), 
script=/home/share/server/test/index2.php
zend_API.c(581) : Actual location (location was relayed)
Last leak repeated 1 time
./zend_execute.c(1940) :  Freeing 0x0820E714 (12 bytes), 
script=/home/share/server/test/index2.php
Last leak repeated 1 time


Here an another example (i think related):


Code-Snipplet-2:

<?php
 
 
class A {
 
  var $_parent;
 
  function setParent(&$obj) {
    $this->_parent =& $obj;
  }
 
 
  function setParentCopy($obj) {
    $this->_parent = $obj;
  }
 
}
 
 
 
$a1 = new A();
$a2 = new A();
 
$a1->setParent($a2); // works
$a1->setParent($a1); // memory leak
$a1->setParentCopy($a1); // memory leak too
 
echo "done";
 
?>


Leak message in error.log:

zend_hash.c(260) :  Freeing 0x085698BC (43 bytes), 
script=/home/share/server/test/index.php
zend_hash.c(176) :  Freeing 0x0856986C (32 bytes), 
script=/home/share/server/test/index.php
./zend_execute.c(425) :  Freeing 0x0856980C (44 bytes), 
script=/home/share/server/test/index.php
zend_variables.c(126) : Actual location (location was 
relayed)
./zend_execute.c(1940) :  Freeing 0x08368BCC (12 bytes), 
script=/home/share/server/test/index.php


-- 
Edit bug report at http://bugs.php.net/?id=16335&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=16335&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=16335&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=16335&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=16335&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=16335&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=16335&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=16335&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=16335&r=submittedtwice

Reply via email to