ID: 26765 Comment by: jaanus at heeringson dot com Reported By: alex_mailbox53 at yahoo dot com Status: Critical Bug Type: Zend Engine 2 problem Operating System: * PHP Version: 5CVS-2004-02-25 New Comment:
Actually, you only create 2 objects in the example above, the initial foo and the bar from foo's constructor. The rest are only references. I still get the "Segmentation fault (11)", and by debugging my own apps i can only concurr that this is not solved. I also sometimes get some kind of race-condition where the apache process heads up to 99.6%, but this occurs rarely. How come the "var_dump() to print_r()" matters? I get segfaults without either (on the sample code). The segfaults only occur the second time the code is run on the same process, not when initially loading the page. Previous Comments: ------------------------------------------------------------------------ [2004-02-29 16:46:44] awulf at ev1 dot net -- quoting [EMAIL PROTECTED] $t = &new foo(); $t->bar->add(new foo()); var_dump($t); ?> This yields object foo is being destroyed. object bar is being destroyed. object foo is being destroyed. object bar is being destroyed. -- end quote this looks like it's doing the right thing to me. first you make a foo, which in its constructor makes a bar. so you have 2 objects. then you add another foo to the first foo's bar, which then creates another bar, so you have 4 objects total. then they all get destroyed. looks good to me, yeah? ------------------------------------------------------------------------ [2004-02-08 22:06:35] [EMAIL PROTECTED] And several more notes follow. - It seems circular references are now properly handled with the new destructor code recently brought into the engine by Zeev. - As you know, in php5 objects are assigned to variables by reference, so it'd be a fair comparison if the script goes like this: <?php class foo { var $bar = false; var $parent = false; function foo() { $this->bar = &new bar($this); } function __destruct() { echo "object ".__CLASS__." is being destroyed.\n"; } } class bar { var $foo = false; var $items = array(); function bar(&$foo) { $this->foo = &$foo; } function add(&$item) { $this->items[] = &$item; $item->parent = &$this->foo; } function __destruct() { echo "object ".__CLASS__." is being destroyed.\n"; } } $t = &new foo(); $t->bar->add(new foo()); var_dump($t); ?> This yields object foo is being destroyed. object bar is being destroyed. object foo is being destroyed. object bar is being destroyed. It looks like these objects have been destroyed twice... - I wasn't able to reproduce the segfault even though I changed var_dump() to print_r(). ------------------------------------------------------------------------ [2004-02-08 21:43:31] [EMAIL PROTECTED] The leaks are caused by circular references. So the only remaining issue is the segfault bug. Perhaps related to bug #25975 ------------------------------------------------------------------------ [2004-02-08 11:51:51] [EMAIL PROTECTED] Here is the backtrace when print_r() is used: [Switching to Thread 16384 (LWP 27314)] 0x082cd5a8 in zend_std_compare_objects (o1=0x40e4306c, o2=0xbfffd580) at /usr/src/web/php/php5/Zend/zend_object_handlers.c:843 843 if (zobj1->ce != zobj2->ce) { (gdb) bt #0 0x082cd5a8 in zend_std_compare_objects (o1=0x40e4306c, o2=0xbfffd580) at /usr/src/web/php/php5/Zend/zend_object_handlers.c:843 #1 0x082bba58 in zend_print_zval_r_ex (write_func=0x8285769 <php_body_write_wrapper>, expr=0x40e4306c, indent=0) at /usr/src/web/php/php5/Zend/zend.c:366 #2 0x082bb99b in zend_print_zval_r (expr=0x40e4306c, indent=0) at /usr/src/web/php/php5/Zend/zend.c:342 #3 0x0820b566 in zif_print_r (ht=1, return_value=0x40e439d4, this_ptr=0x0, return_value_used=0) at /usr/src/web/php/php5/ext/standard/basic_functions.c:2570 #4 0x082dd654 in zend_do_fcall_common_helper (execute_data=0xbfffd7c0, opline=0x40e42f54, op_array=0x40e42674) at /usr/src/web/php/php5/Zend/zend_execute.c:2558 #5 0x082ddc8a in zend_do_fcall_handler (execute_data=0xbfffd7c0, opline=0x40e42f54, op_array=0x40e42674) at /usr/src/web/php/php5/Zend/zend_execute.c:2700 #6 0x082da498 in execute (op_array=0x40e42674) at /usr/src/web/php/php5/Zend/zend_execute.c:1272 #7 0x082bcad3 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/web/php/php5/Zend/zend.c:1051 #8 0x08285fd8 in php_execute_script (primary_file=0xbffffbc0) at /usr/src/web/php/php5/main/main.c:1641 #9 0x080b776c in main (argc=2, argv=0xbffffc54) at /usr/src/web/php/php5/sapi/cli/php_cli.c:941 ------------------------------------------------------------------------ [2004-02-04 20:42:09] [EMAIL PROTECTED] Latest CVS checkout of HEAD today doesn't show any leaks anymore, but the output is still incorrect. (or it's incorrect with PHP 4, who knows :). And changing that var_dump() -> print_r() causes segfault.. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/26765 -- Edit this bug report at http://bugs.php.net/?id=26765&edit=1