php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36828 segfault in special __destruct circumstances
Submitted: 2006-03-23 01:58 UTC Modified: 2006-03-23 16:24 UTC
From: locke at pushby dot com Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 5.1.2 OS: Multiple: FreeBSD,Linux,Windows
Private report: No CVE-ID: None
 [2006-03-23 01:58 UTC] locke at pushby dot com
Description:
------------
Segfault occurs in object destructor when a number of conditions appear together.  See code comment for details.

This might be related to bug #36006 (http://bugs.php.net/bug.php?id=36006), but it isn't clear since commenting out *either* of the two lines indicated in the code below avoids the segfault.

Reproduce code:
---------------
<?php

class segfault {
    protected $message = null;
    protected $foo     = null;

    public function __construct ($message) {
        $this->foo = new foo ($this);
        $this->message = $message;
    }

    public function __destruct () {
        // If *either* of the following two lines are omitted, we don't segfault ...
        unset($this->foo);
        print( "MESSAGE: $this->message \n" );
    }
}

class foo {
    protected $ob_ref = null;

    public function __construct ($ob_ref) {
        $this->ob_ref = $ob_ref;
    }
}

$segf = new segfault("ACK");
unset($segf);

?>

Expected result:
----------------
Code prints:
"MESSAGE: ACK"

Actual result:
--------------
No message is printed.  PHP terminates with Segmentation Fault (or Bus error depending on the hardware). 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-23 02:12 UTC] judas dot iscariote at gmail dot com
# php5-debug destruct.php
MESSAGE: ACK
PHP 5.1.3RC2-dev (cli) (built: Mar 22 2006 21:01:28) (DEBUG)

no segfault , works as you expected.
 [2006-03-23 10:09 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [2006-03-23 16:24 UTC] locke at pushby dot com
Tested and works in 5.1.3RC2-dev.  Thanks.  Will look forward to next release build.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 23:01:33 2025 UTC