php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22855 Memory corruption when dealing with cyclic references between objects
Submitted: 2003-03-24 12:06 UTC Modified: 2003-03-24 18:11 UTC
From: knizhnik at garret dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.1 OS: Windows and Linux
Private report: No CVE-ID: None
 [2003-03-24 12:06 UTC] knizhnik at garret dot ru
PHP is using reference counter garbage collection so it is not able to deallocate objects with cyclic references. But
it should not be a reason for corrupting memory. The following example cause either loosing value of object property either segmentation fault at PHP 4.3.1 and PHP-4.3.2RC1. The fault takes place after inserting 65533
objects (0xfffd - looks like somewhere short type is used:).
In first case after inserting about 65k of objects the system reports "PHP Notice:  Undefined property:" when 
accessing "opened" field in storeObject.


<?php


class Storage { 
    var $opened;
    var $count;

    function Storage() { 
        $this->objByOidMap = array();
        $this->opened = true;
        $this->count = 0;
    }

    function storeObject(&$obj) {
        if ($this->opened) { 
            if ($obj->__oid__ == 0) {   
                $this->count += 1;
                $obj->__oid__ = $this->count;
                $obj->__storage__ = &$this;
                $this->objByOidMap[$obj->__oid__] = &$obj;
            }
        }
    }
}

class Object {
    var $__storage__;
    var $__oid__;
}

$storage = &new Storage();
for ($i = 0; $i < 100000; $i++) {
    print("i=$i\n");
    $obj = &new Object();
    $storage->storeObject($obj);
}

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-24 18:11 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.


There are at least 3 or 4 reports similar or about exactly the same issue..so please search the bug database first.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 11:01:28 2024 UTC