Fixed bug #60139 (Anonymous functions create cycles not detected by the GC)

This commit is contained in:
Dmitry Stogov 2011-11-02 06:31:33 +00:00
parent 8b4890e18e
commit e95bb57da9
3 changed files with 45 additions and 0 deletions

2
NEWS
View file

@ -3,6 +3,8 @@ PHP NEWS
?? ??? 2011, PHP 5.3.9
- Core:
. Fixed bug #60139 (Anonymous functions create cycles not detected by the
GC). (Dmitry)
. Fixed bug #60120 (proc_open's streams may hang with stdin/out/err when
the data exceeds or is equal to 2048 bytes). (Pierre, Pascal Borreli)
. Fixed bug #60019 (Function time_nanosleep() is undefined on OS X). (Ilia)

30
Zend/tests/bug60139.phpt Normal file
View file

@ -0,0 +1,30 @@
--TEST--
Bug #60139 (Anonymous functions create cycles not detected by the GC)
--FILE--
<?php
class Foo {
public $x;
public function __construct() {
$this->x = function() {};
}
}
class Bar {
public $x;
public function __construct() {
$self = $this;
$this->x = function() use ($self) {};
}
}
gc_collect_cycles();
new Foo;
var_dump(gc_collect_cycles());
new Bar;
var_dump(gc_collect_cycles());
?>
--EXPECT--
int(0)
int(2)

View file

@ -280,6 +280,18 @@ static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp TSRMLS_
}
/* }}} */
static HashTable *zend_closure_get_properties(zval *obj TSRMLS_DC) /* {{{ */
{
zend_closure *closure = (zend_closure *)zend_object_store_get_object(obj TSRMLS_CC);
if (GC_G(gc_active)) {
return (closure->func.type == ZEND_USER_FUNCTION) ? closure->func.op_array.static_variables : NULL;
}
return closure->std.properties;
}
/* }}} */
/* {{{ proto Closure::__construct()
Private constructor preventing instantiation */
ZEND_METHOD(Closure, __construct)
@ -316,6 +328,7 @@ void zend_register_closure_ce(TSRMLS_D) /* {{{ */
closure_handlers.clone_obj = NULL;
closure_handlers.get_debug_info = zend_closure_get_debug_info;
closure_handlers.get_closure = zend_closure_get_closure;
closure_handlers.get_properties = zend_closure_get_properties;
}
/* }}} */