php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16335 memory leak when passing object
Submitted: 2002-03-28 17:02 UTC Modified: 2002-03-28 19:13 UTC
From: roland at inkoeln dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.1.1 OS: linux
Private report: No CVE-ID: None
 [2002-03-28 17:02 UTC] roland at inkoeln dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-28 19:13 UTC] yohgaki@php.net
Please do not submit the same bug more than once.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 02:01:30 2019 UTC